Latex如何设置中文字体和英文字体。

作成日: 2025年4月4日

使用モデル O1 by Chat01

質問

Latex如何设置中文字体和英文字体。

思考

Setting up fonts

I’m detailing how to specify Chinese and English fonts in LaTeX by utilizing the XeLaTeX engine and configuring font settings effectively.

Setting the scene

I’m thinking about how to set both Chinese and English fonts in LaTeX, emphasizing the use of the XeLaTeX engine to manage font settings effectively.

Reasoned for a couple of seconds

回答

在 LaTeX 中,可以使用 ctex 宏包来设置中文字体,同时使用 fontspec 宏包来设置英文字体。下面是一个简单的示例,展示了如何同时设置中文字体和英文字体:

latex
\documentclass{article} \usepackage{ctex} % 导入中文支持宏包 \usepackage{fontspec} % 导入字体设置宏包 % 设置中文字体 \setCJKmainfont{SimSun} % 设置中文主字体为宋体 % 设置英文字体 \setmainfont{Times New Roman} % 设置英文字体为 Times New Roman \begin{document} 这是中文部分,使用宋体。 This is an English part, using Times New Roman. \end{document}

解释:

  1. \usepackage{ctex}:导入 ctex 宏包,提供中文支持。
  2. \setCJKmainfont{SimSun}:设置中文主字体为宋体(可以根据需要选择其他中文字体,如 KaiTiFangSong 等)。
  3. \setmainfont{Times New Roman}:设置英文字体为 Times New Roman。

你可以根据自己的需要调整字体,确保所选字体已经安装在你的系统中。

質問

latex如何设置表格通栏

思考

Making use of packages

I'm considering the use of the "tabularx" package to create a table that spans the full page width in LaTeX, ensuring it fits the text area appropriately.

Maximizing table width

To span the entire text width, I’m using the "array" package or "tabularx" with specific column specifications. For multi-page documents, the "longtable" environment is the best option.

Choosing the right approach

For single-column layouts, "tabularx" is optimal for full width. In two-column settings, "table*" or "figure*" environments are preferable. This effectively covers layout options.

Reasoned about LaTeX table spanning for 10 seconds

回答

在单栏文档中,如果想让表格宽度占据整个文本区域(即“通栏”),可以直接将表格宽度设置为 \textwidth。如果是双栏文档并希望表格横跨两栏,则可以使用 table* 环境。下面分别给出两种常见的做法。


一、单栏文档中的通栏表格

对于单栏文档(如 article),最常见的方式是使用 tabularx 环境,并将表格总宽度指定为 \textwidth。示例代码如下:

latex
\documentclass{article} \usepackage{tabularx} \begin{document} \begin{table}[htbp] \centering % X列格式表示该列可自动伸缩来适应表格总宽度 \begin{tabularx}{\textwidth}{|X|X|X|} \hline 列1 & 列2 & 列3 \\ \hline 第一行内容 & 第二列内容 & 第三列内容 \\ \hline 第二行内容 & 第二列内容 & 第三列内容 \\ \hline \end{tabularx} \caption{一个通栏表格示例(单栏)} \label{tab:fullwidth_single} \end{table} \end{document}

说明

  1. tabularx 包能根据列内容自动调整列宽,从而使表格填满指定的宽度(这里是 \textwidth)。
  2. 在列格式中,用 X 表示可自动伸缩的列;如果列数较多,需要合理组合如 |X|c|X| 等以满足布局需求。

二、双栏文档中的通栏表格

如果你使用的是双栏文档(如 \documentclass[twocolumn]{article}\documentclass{twocolumn}),想让表格跨越两栏,可以将 table 环境改为 table*,并同样使用 tabularxtabular* 指定表格总宽度为 \textwidth。示例如下:

latex
\documentclass[twocolumn]{article} \usepackage{tabularx} \begin{document} \begin{table*}[htbp] \centering \begin{tabularx}{\textwidth}{|X|X|X|} \hline 列1 & 列2 & 列3 \\ \hline 第一行内容 & 第二列内容 & 第三列内容 \\ \hline 第二行内容 & 第二列内容 & 第三列内容 \\ \hline \end{tabularx} \caption{一个通栏表格示例(双栏)} \label{tab:fullwidth_double} \end{table*} \end{document}

说明

  1. 在双栏模式下,只有使用 table* 环境才能让表格横跨两栏。
  2. 注意双栏环境下,表格的放置位置可能会受到排版机制的限制,LaTeX 可能会将其浮动到合适的页面(有时会跑到文档末尾)。可根据需要使用不同的浮动选项(如 [htbp])或加载额外宏包(如 stfloats)进行进一步调整。

小结

  • 单栏文档:直接在 tabularxtabular* 中指定 \textwidth 既可实现通栏表格。
  • 双栏文档:将 table 改为 table*,并同样指定表格宽度为 \textwidth
  • 如果需要更灵活的列宽分配,可以结合 tabularx 提供的 X 列格式,或者使用 tabular* 配合 \extracolsep{\fill} 等技巧。

質問

请修改下面的Latex表格,让其通栏。
\begin{table}[htbp]
\bicaption{近机位信息表}{Table of near gate information}
\centering
% 调整表格,修改数字即可
\setlength{\tabcolsep}{1cm} {%表格过窄
\small % Using a smaller font for better readability
\begin{tabular}{p{6cm}|p{6cm}}
\hline
机位编号 & 航空器翼展限制(m) \ \hline
106, 135, 241 & 80 \ \hline
111, 115, 118, 119, 123, 126, 128, 130, 132, 206, 212,
216, 219, 221, 224, 230, 233, 237, 239, 243 & 68.5 \ \hline
113, 114, 116, 117, 125, 127, 129, 131, 134, 208, 214,
215, 217, 218, 229, 232, 235, 236 & 65 \ \hline
101-105, 106L/R, 108L/R, 110, 111L/R, 120-122, 124,
132L/R, 135L/R, 137L/R, 139-145, 201-205, 206L/R,
209-211, 212L/R, 219L/R, 222, 223, 224L/R, 226-228,
230L/R, 233L/R, 237L/R, 239L/R, 241L/R, 243L/R,
245-252 & 36 \ \hline
\end{tabular}}
\label{tab:T2-2-1}
\end{table}

思考

Reorganizing the table

I’m working on a LaTeX table for near gate information. The dimensions are clearly mapped out for aircraft wingspans. Adjustments ensure it spans the entire width, enhancing readability.

Refining table layout

I’m ensuring the table spans the full width, keeping the \bicaption intact. Considering tabularx and \textwidth for precise alignment and prominence.

Reasoned about full-width table in LaTeX for 11 seconds

回答

下面给出了一种将表格改为“通栏”排版的示例。这里我们使用了 tabularx 环境,以便让表格自动适应版心宽度 (\textwidth)。若你的文档是双栏格式,可将 table 替换为 table* 以跨越双栏。

latex
\begin{table}[htbp] \bicaption{近机位信息表}{Table of near gate information} \centering % 使用 tabularx,表格宽度设置为 \textwidth \usepackage{tabularx} % 确保在导言区已加载该宏包 \small \renewcommand{\arraystretch}{1.2} % 可根据需要调整行距 \begin{tabularx}{\textwidth}{X|X} % 两列,各列可自动伸缩 \hline \textbf{机位编号} & \textbf{航空器翼展限制 (m)} \\ \hline 106, 135, 241 & 80 \\ \hline 111, 115, 118, 119, 123, 126, 128, 130, 132, 206, 212, 216, 219, 221, 224, 230, 233, 237, 239, 243 & 68.5 \\ \hline 113, 114, 116, 117, 125, 127, 129, 131, 134, 208, 214, 215, 217, 218, 229, 232, 235, 236 & 65 \\ \hline 101--105, 106L/R, 108L/R, 110, 111L/R, 120--122, 124, 132L/R, 135L/R, 137L/R, 139--145, 201--205, 206L/R, 209--211, 212L/R, 219L/R, 222, 223, 224L/R, 226--228, 230L/R, 233L/R, 237L/R, 239L/R, 241L/R, 243L/R, 245--252 & 36 \\ \hline \end{tabularx} \label{tab:T2-2-1} \end{table}

关键修改说明

  1. 使用 tabularx 宏包
    在导言区(\documentclass 后面)添加:

    latex
    \usepackage{tabularx}
  2. 将表格宽度设为 \textwidth
    tabularx 环境中,使用

    latex
    \begin{tabularx}{\textwidth}{X|X}

    这样即可让表格自动扩展到页面的可用宽度。

  3. 列格式使用 X
    与普通 tabular 不同,tabularx 中的 X 列可自动伸缩以适应设定的总宽度,无需手动设列宽。

  4. 行距与字体大小

    • 通过 \small 控制整体字体变小。
    • 使用 \renewcommand{\arraystretch}{1.2} 可适度增大行距,提高可读性。
  5. 双栏情况
    如果你的文档是双栏排版(如 \documentclass[twocolumn]{article}),请将外层的

    latex
    \begin{table}[htbp]

    更改为

    latex
    \begin{table*}[htbp]

    这样才能使表格跨越双栏。

这样调整后,表格就会“通栏”排版并且能够自适应页面宽度。

質問

请修改下面的Latex表格,让其通栏:
\begin{table}[htbp]
\centering
\bicaption{飞机机型与翼展表}{Table of aircraft type and wingspan}
\setlength{\tabcolsep}{0.5cm}{%表格过窄
\small % Using a smaller font for better readability
\begin{tabular}{cccccc}
\toprule
\textbf{机型} & \textbf{翼展 (m)} & \textbf{机位}&\textbf{机型} & \textbf{翼展 (m)}& \textbf{机位} \
\midrule
B738M & 约 35.9 & 中 & A320 & 约 34.1 & 中 \
A319 & 约 34.1 & 中 & A332 & 约 60.3 &大\
A333 & 约 60.3 & 大& B738 & 约 35.8 & 中 \
B788 & 约 60.1 & 大 & A320-NEO & 约 35.8 & 中 \
A319-NEO & 约 35.8 & 中& A321 & 约 34.1 & 中 \
B737 & 约 35.8 & 中 & B787-10 & 约 60.1 & 大 \
B739 & 约 35.8 & 中 & B789 & 约 60.1 & 大 \
ARJ21 & 约 27.3 & 小& EMB190 & 约 28.7 & 小 \
A359 & 约 64.8 & 大& B772 & 约 60.9 &大 \
A321-NEO & 约 35.8 & 中 & COMAC-C919 & 约 35.8 & 中 \
\bottomrule
\end{tabular}}
\label{tab:T3-4-1}
\end{table}

思考

Transposing the table

I'm working on converting the LaTeX table into pseudocode, ensuring it spans the full width. This involves simplifying the layout for clarity.

Expanding the table

I’m thinking of tweaking the table to stretch the full page, making information like aircraft type and wingspan easier to compare and understand.

Maximizing table width

I’m assessing tabularx to stretch each column to match the page width. This approach avoids distortion and keeps the layout balanced and readable.

Reasoned for 20 seconds

回答

下面给出了一种调整方法,使得表格能够“通栏”排版并自适应页面宽度。核心思路是使用 tabularx 环境代替普通的 tabular,并将表格宽度设为 \textwidth。这样可以根据内容自动分配列宽,真正占满版心。

如果你的文档是双栏模式(如 \documentclass[twocolumn]{article}),请将外层的 table 环境改为 table*,例如 \begin{table*}[htbp] ... \end{table*},以实现跨两栏显示。

下面是示例修改后的代码(假设是单栏文档):

latex
% ---------------------------------------------------------------------------- % 在导言区(\documentclass 后面)确保加载 tabularx 宏包 % \usepackage{tabularx} % \usepackage{booktabs} % 如果要用 \toprule 等命令 % ---------------------------------------------------------------------------- \begin{table}[htbp] \centering \bicaption{飞机机型与翼展表}{Table of aircraft type and wingspan} % 让表格变小一些,可根据需要调整字号 \small % 可适当增大行距以改善可读性 \renewcommand{\arraystretch}{1.2} % 使用 tabularx,并设置总宽度为 \textwidth % 每列都用 X 表示可自动伸缩 % 如果想让文字居中,可用 >{\centering\arraybackslash}X \begin{tabularx}{\textwidth}{>{\centering\arraybackslash}X >{\centering\arraybackslash}X >{\centering\arraybackslash}X >{\centering\arraybackslash}X >{\centering\arraybackslash}X >{\centering\arraybackslash}X} \toprule \textbf{机型} & \textbf{翼展 (m)} & \textbf{机位} & \textbf{机型} & \textbf{翼展 (m)} & \textbf{机位} \\ \midrule B738M & 约 35.9 && A320 & 约 34.1 &\\ A319 & 约 34.1 && A332 & 约 60.3 &\\ A333 & 约 60.3 && B738 & 约 35.8 &\\ B788 & 约 60.1 && A320-NEO & 约 35.8 &\\ A319-NEO & 约 35.8 && A321 & 约 34.1 &\\ B737 & 约 35.8 && B787-10 & 约 60.1 &\\ B739 & 约 35.8 && B789 & 约 60.1 &\\ ARJ21 & 约 27.3 && EMB190 & 约 28.7 &\\ A359 & 约 64.8 && B772 & 约 60.9 &\\ A321-NEO & 约 35.8 && COMAC-C919 & 约 35.8 &\\ \bottomrule \end{tabularx} \label{tab:T3-4-1} \end{table}

关键点说明

  1. 导言区加载宏包:

    latex
    \usepackage{tabularx} \usepackage{booktabs} % 如果需要 \toprule, \midrule, \bottomrule 等命令
  2. tabularx 的使用:

    • {cccccc} 替换为 {>{\centering\arraybackslash}X ... }(共 6 个 X),表示 6 列都可自动伸缩。
    • 如果需要文字左对齐,可以改用 >{\raggedright\arraybackslash}X;需要居右则用 >{\raggedleft\arraybackslash}X;居中则用 >{\centering\arraybackslash}X
  3. 宽度设置:
    \begin{tabularx}{\textwidth}{...} 指定表格总宽度为版心宽度(\textwidth),从而实现“通栏”。

  4. 字体和行距:

    • 通过 \small 让表格整体字号略小。
    • \renewcommand{\arraystretch}{1.2} 可适当增大表格的行距。
  5. 双栏情况:
    若是双栏文档,需要用 \begin{table*}[htbp] 替换 \begin{table}[htbp] 才能让表格跨越两栏。

按上述方式修改后,表格即可根据内容自动分配列宽,真正占满页面的可用宽度。

このQ&Aを共有