Latex 三线表制作,合并单元格, 加粗, 旋转等基于Overleaf

本文详细介绍了在LaTeX中创建和格式化表格的方法,包括基本的浮动体参数控制、经典三线表的制作、线条加粗、四线表、列合并、行合并、行间距调整、字体样式增强以及大表格的旋转。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1 基础三线表

1.1  表格和图片中的h t b p 和!分别代表什么意思:

这些统称为Latex的浮动体参数,用于控制当前对象(图、表)等在页面上的相对位置。

  • h(here):代表将浮动体放在页面上的当前位置;
  • t(top):代表将浮动体放在当前页面顶部;
  • b(bottom):代表将浮动体放置在当前页面的底部;
  • p:表示将浮动体放置在一页上。

一般情况下,使用[!htbp]表示浮动体按照当前位置、页面顶部、页面底端和另一页搜寻最优位置。

 1.2、经典三线表

 经典三线格无需依赖任何外置包

\documentclass{article}

\begin{document}


\begin{table}[!htbp]
\caption{\textbf{Classical table}}%title
\centering
\begin{tabular}{cccc}% four columns
\hline %begin the first line
T 1 & T 2 & T 3 & T 4 \\
\hline %begin the second line
D1 & D2 & D3 & D4 \\
D5 & D6 & D7 & D8 \\
\hline %begin the third line
\end{tabular}
\end{table}
 
\end{document}

 效果图如下:

 1.3 表格线条加粗

Latex 代码段:加粗主要导入的包有 \usepackage{booktabs}, 其中第一条线和最后一条线设置为2pt的线宽。

\documentclass{article}
\usepackage{booktabs} % provide \toprule, \midrule, bottomrule

\begin{document}


\begin{table}[!htbp]
\caption{\textbf{Classical table}}%title
\centering
\begin{tabular}{cccc}% four columns
\toprule[2pt] %change the first line to \toprule
T 1 & T 2 & T 3 & T 4 \\
\midrule %change the second line to midrule
D1 & D2 & D3 & D4 \\
D5 & D6 & D7 & D8 \\
\bottomrule[2pt] %change the third line to bottomrule
\end{tabular}
\end{table}

\end{document}

 1.4 经典四线表(加粗)

使用四线表的方式比较简单,即多加一行\midrule就能解决:

\documentclass{article}
\usepackage{booktabs} % provide \toprule, \midrule, bottomrule

\begin{document}
\begin{table}[!htbp]
\caption{\textbf{Classical table}}%title
\centering
\begin{tabular}{cccc}% four columns
\toprule[2pt] %change the first line to \toprule
T 1 & T 2 & T 3 & T 4 \\
\midrule %change the second line to midrule
D1 & D2 & D3 & D4 \\
D5 & D6 & D7 & D8 \\
\midrule
D9 & D10 & D11 & D12 \\
\bottomrule[2pt] %change the third line to bottomrule
\end{tabular}
\end{table}

\end{document}

 2 进阶三线表(论文中的三线表)

2.1 合并列(两列)

使用 \multicolumn合并行两列

 \documentclass{article}
\usepackage{booktabs} % provide \toprule, \midrule, bottomrule

\begin{document}
\begin{table}[!htbp]
\caption{\textbf{Classical table}}%title
\centering
\begin{tabular}{cccc}% four columns
\toprule[2pt] %change the first line to \toprule
\multicolumn{2}{c}{T1}  & \multicolumn{2}{c}{T2} \\
\midrule %change the second line to midrule
D1 & D2 & D3 & D4 \\
D5 & D6 & D7 & D8 \\
\bottomrule[2pt] %change the third line to bottomrule
\end{tabular}
\end{table}

\end{document}

 2.2 合并列(三列)

注意,这里要修改一下表格整体的列数

\documentclass{article}
\usepackage{booktabs} % provide \toprule, \midrule, bottomrule

\begin{document}
\begin{table}[!htbp]
\caption{\textbf{Classical table}}%title
\centering
\begin{tabular}{ccccc}% four columns
\toprule[2pt] %change the first line to \toprule
\multicolumn{2}{c}{T1}  & \multicolumn{3}{c}{T2} \\
\midrule %change the second line to midrule
D1 & D2 & D3 & D4 & D9\\
D5 & D6 & D7 & D8 & D10\\
\bottomrule[2pt] %change the third line to bottomrule
\end{tabular}
\end{table}

\end{document}

 2.3 合并行

注意,这里需要导入\usepackage{multirow},便于后续的cline(插入不同长短的线)以及合并行操作。

2.3.1 \cline参数

例如\cline{2-5},代表了该位置从第二列到第五列画线

 \documentclass{article}
\usepackage{booktabs} % provide \toprule, \midrule, bottomrule
\usepackage{multirow}

\begin{document}
\begin{table}[!htbp]
\caption{\textbf{Classical table}}%title
\centering
\begin{tabular}{ccccc}% four columns
\toprule[2pt] %change the first line to \toprule
\multirow{2}*{T0} & \multicolumn{2}{c}{T1}  & \multicolumn{2}{c}{T2} \\
& D2 & D3 & D4 & D9\\
\cline{2-5} %change the second line to midrule
D5 & D6 & D7 & D8 & D10\\
D11 & D12 & D13 & D14 & D15\\
\bottomrule[2pt] %change the third line to bottomrule
\end{tabular}
\end{table}

\end{document}

 2.4 调整行间距,列间距等

使用\renewcommand\arraystretch{}调整行间距

\documentclass{article}
\usepackage{booktabs} % provide \toprule, \midrule, bottomrule
\usepackage{multirow}
 

\begin{document}
\begin{table}[!htbp]
\renewcommand\arraystretch{2.0}
\caption{\textbf{Classical table}}%title
\centering
\begin{tabular}{ccccc}% four columns
\toprule[2pt] %change the first line to \toprule
\multirow{2}*{T0} & \multicolumn{2}{c}{T1}  & \multicolumn{2}{c}{T2} \\
& D2 & D3 & D4 & D9\\
\cline{2-5} %change the second line to midrule
D5 & D6 & D7 & D8 & D10\\
D11 & D12 & D13 & D14 & D15\\
\bottomrule[2pt] %change the third line to bottomrule
\end{tabular}
\end{table}


\end{document}

2.5 表格字体加粗 ,加横线

写论文时为了突出方法的有点,可以从大量的数据中表出最大值或者第二大值,使得表格的阅读性更佳。

\documentclass{article}
\usepackage{booktabs} % provide \toprule, \midrule, bottomrule
\usepackage{multirow}
 

\begin{document}
\begin{table}[!htbp]
\renewcommand\arraystretch{2.0}
\caption{\textbf{Classical table}}%title
\centering
\begin{tabular}{ccccc}% four columns
\toprule[2pt] %change the first line to \toprule
\multirow{2}*{T0} & \multicolumn{2}{c}{T1}  & \multicolumn{2}{c}{T2} \\
& D2 & D3 & D4 & D9\\
\cline{2-5} %change the second line to midrule
\underline{D5} & \underline{D6} & D7 & D8 & D10\\
\textbf{D11} & \textbf{D12} & D13 & D14 & D15\\
\bottomrule[2pt] %change the third line to bottomrule
\end{tabular}
\end{table}


\end{document}

 3 表格翻转

表格过大时需要进行翻转操作,旋转90°。使用sidewaystable代替table环境。

 \documentclass{article}
\usepackage{booktabs} % provide \toprule, \midrule, bottomrule
\usepackage{multirow}
\usepackage[figuresright]{rotating}
 

\begin{document}
\begin{sidewaystable}[!htbp]
\renewcommand\arraystretch{2.0}
\caption{\textbf{Classical table}}%title
\centering
\begin{tabular}{ccccc}% four columns
\toprule[2pt] %change the first line to \toprule
\multirow{2}*{T0} & \multicolumn{2}{c}{T1}  & \multicolumn{2}{c}{T2} \\
& D2 & D3 & D4 & D9\\
\cline{2-5} %change the second line to midrule
\underline{D5} & \underline{D6} & D7 & D8 & D10\\
\textbf{D11} & \textbf{D12} & D13 & D14 & D15\\
\bottomrule[2pt] %change the third line to bottomrule
\end{tabular}
\end{sidewaystable}


\end{document}

Reference:

reference1

reference2

reference3

<think>好的,我现在需要帮助用户解决在LaTeX中创建和自定义的问题。首先,用户提到他们参考了站内的两个引用,其中引用[1]是关于LaTeX入门的,而引用[2]给出了一个列对齐方式的示例代码。用户需要具体的步骤和示例代码,所以我得详细说明如何创建,并展示如何自定义对齐、边框、合并单元等。 首先,我应该从基础开始,介绍LaTeX中创建的基本环境,比如tabular环境。需要提到必选参数是列式定义,比如l、c、r对应左中右对齐,以及如何添加竖线边框。然后,给出一个简单的例子,比如一个三列的,带有水平和垂直边框,并解释代码中的每个部分。 接下来,用户可能需要更复杂的自定义,比如使用array包来定义新的列类型,或者使用tabularx包来实现自动调整宽度的。这里需要提到如何引入这些包,并展示相应的示例代码。例如,使用tabularx的X列来自动填充宽度,或者使用p{宽度}来指定固定宽度。 然后,合并单元是一个常见需求,应该介绍multirow和multicolumn宏包的使用方法。给出跨行和跨列的示例,比如合并两行一列,或者跨越多列,并注意需要引入相应的包。 关于样式美化,可以讨论如何添加头、调整行高、设置单元内边距,以及使用booktabs包来改善线的外观,比如用\toprule、\midrule和\bottomrule来替代传统的横线。 最后,需要提醒用户编译时需要添加必要的宏包,并建议参考相关文档。同时,根据用户提供的引用[2],他们可能已经看到过类似复杂的列定义,所以在示例中可以引用那个例子,比如使用@{}}来调整两侧的边距,或者使用多个c列。 现在需要确保所有示例代码的LaTeX语法正确,符合用户提到的系统级指令,比如行内公式用$...$,独立公式用$$...$$,但代码可能不需要这些,主要是正确的tabular或tabularx环境。同时,回答要使用中文,结构清晰,分步骤说明,并在最后生成相关问题。 可能需要注意用户提到的引用标记,比如在回答中引用[^1]和[^2],但根据用户的问题,引用[2]是关于对齐的示例,所以在讲解列对齐时应该提到这一点,并在适当的位置添加引用标识。 总结步骤: 1. 基本创建:使用tabular环境,列对齐,边框。 2. 列式自定义:使用p{}、tabularx的X列。 3. 合并单元:multirow和multicolumn。 4. 样式美化:添加头、调整线型、使用booktabs。 5. 提供示例代码,并确保正确性。 6. 添加相关问题,如合并单元、处理长文本、调整行高等。 现在需要组织这些内容,确保每个部分有示例代码,并正确引用用户提供的参考文献,特别是在列对齐部分提到引用[2]中的例子。同时,检查是否有遗漏的部分,比如标题和标签,这些可能需要使用table环境和caption命令。 可能还需要提到如何调整的位置(如使用h、t、b、!等参数),或者如何处理过宽的问题,比如调整缩放或换行。但根据用户的问题,可能集中在创建和基本自定义上,所以需要平衡详细程度,避免过于深入。 最后,生成的相关问题需要围绕的进一步自定义和常见问题,比如调整对齐、处理复杂结构、样式优化等。</think>在 LaTeX 中创建和自定义可通过以下方法实现,结合示例代码说明: --- ### 一、基础创建 使用 `tabular` 环境定义,语法为: ```latex \begin{tabular}{列式定义} 内容 \end{tabular} ``` **示例**:三列左对齐,含边框 ```latex \begin{tabular}{|l|c|r|} \hline 左对齐 & 居中 & 右对齐 \\ \hline A & B & C \\ D & E & F \\ \hline \end{tabular} ``` - `|` 示垂直边框,`\hline` 示水平边框 - `l/c/r` 定义列对齐方式[^2] --- ### 二、自定义列式 #### 1. 固定宽度列 使用 `p{宽度}` 或 `m{宽度}`(需 `array` 包): ```latex \begin{tabular}{|p{2cm}|m{3cm}|} \hline 固定宽度列 & 垂直居中列 \\ \hline 文本较长时会自动换行 & 内容垂直居中 \\ \hline \end{tabular} ``` #### 2. 自动调整列宽 使用 `tabularx` 包的 `X` 列(需引入包 `\usepackage{tabularx}`): ```latex \begin{tabularx}{\textwidth}{|X|X|X|} \hline 列1 & 列2 & 列3 \\ \hline 内容自动填充宽度 & 根据文本调整 & 多列均衡分配 \\ \hline \end{tabularx} ``` --- ### 三、合并单元 #### 1. 跨列合并 使用 `\multicolumn`: ```latex \begin{tabular}{|l|l|l|} \hline \multicolumn{2}{|c|}{合并两列} & 单独列 \\ \hline A & B & C \\ \hline \end{tabular} ``` #### 2. 跨行合并 使用 `multirow` 包(需引入包 `\usepackage{multirow}`): ```latex \begin{tabular}{|l|l|} \hline \multirow{2}{*}{合并两行} & 第一行 \\ & 第二行 \\ \hline \end{tabular} ``` --- ### 四、样式美化 #### 1. 添加头与标题 使用 `table` 环境包裹并添加标题: ```latex \begin{table}[ht] \centering \caption{示例} \begin{tabular}{|l|l|} \hline 列1 & 列2 \\ \hline A & B \\ \hline \end{tabular} \label{tab:example} \end{table} ``` #### 2. 专业横线样式 使用 `booktabs` 包优化横线(需引入包 `\usepackage{booktabs}`): ```latex \begin{tabular}{ccc} \toprule 标题1 & 标题2 & 标题3 \\ \midrule 内容1 & 内容2 & 内容3 \\ \bottomrule \end{tabular} ``` --- ### 五、完整示例代码 ```latex \documentclass{article} \usepackage{tabularx, multirow, booktabs} \begin{document} \begin{table}[ht] \centering \caption{自定义示例} \begin{tabularx}{0.8\textwidth}{l X r} \toprule \textbf{姓名} & \textbf{描述} & \textbf{分数} \\ \midrule 张三 & 多行文本示例:LaTeX 设计需要兼顾内容可读性与排版美观性。 & 95 \\ \multirow{2}{*}{李四} & 第一行描述 & 88 \\ & 第二行补充说明 & 90 \\ \bottomrule \end{tabularx} \end{table} \end{document} ``` ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

某崔同学

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值