Latex使用技巧——表格

Latex使用技巧——表格Latex 表格使用技巧及常用模板的代码 latex 表格

大家好,欢迎来到IT知识分享网。

本文对Latex中的表格使用进行了简单介绍,包括如何合并单元格、设置列宽等,同时提供了一些使用模板的代码。

基本语法

  1. Latex中通常使用 tabular 环境创建表格,基本语法如下:
\begin{ 
   tabular}{ 
   |列格式|列格式|列格式|} 单元格内容 & 单元格内容 & 单元格内容 \\ 单元格内容 & 单元格内容 & 单元格内容 \\ \end{ 
   tabular} 
  1. 对齐方式
  • l:左对齐(left)
  • c:居中对齐(center)
  • r:右对齐(right)
  1. 使用技巧
  • 合并行:\multirow{合并行数}{对齐方式}{内容}
  • 合并列:\multicolumn{合并列数}{对齐方式}{内容}
  • 行间水平线: \hline 添加水平线
  • 调整列宽:p{宽度}
  • 单元格内容换行:\newline 或 \ 实现

表格模板

  1. 基本三线表
\begin{ 
   tabular}{ 
   ccc} \toprule Column 1 & Column 2 & Column 3 \\ % Table header \midrule Data 1 & Data 2 & Data 3 \\ %第一行数据 Data 4 & Data 5 & Data 6 \\ %第二行数据 Data 7 & Data 8 & Data 9 \\ %第三行数据 \bottomrule \end{ 
   tabular} 
  1. 完整三线格模板(用于论文)
  • 使用table环境设置表格的浮动环境
  • 浮动位置参数:h (here):尝试将浮动对象放置在当前位置;t (top):尝试将浮动对象放置在页面的顶部;b (bottom):尝试将浮动对象放置在页面的底部;p (page of floats):将浮动对象放置在一个专门用于浮动对象的页面上;!:忽略某些内部参数限制,强制更严格地尝试放置浮动对象;H (from float package):强制将浮动对象放置在当前位置(需要使用 \usepackage{float} 宏包)。
  • 正文中引用:\ref{表格label}
\begin{ 
   table}[htbp] % 尝试将表格放置在合适的位置 \centering % 使表格居中 \begin{ 
   tabular}{ 
   ccc} % 定义一个有三列的表格 \toprule Column 1 & Column 2 & Column 3 \\ % 表头 \midrule Data 1 & Data 2 & Data 3 \\ % 第一行数据 Data 4 & Data 5 & Data 6 \\ % 第二行数据 Data 7 & Data 8 & Data 9 \\ % 第三行数据 \bottomrule \end{ 
   tabular} \caption{ 
   An example table} % 表格标题 \label{ 
   tab:example} % 表格标签,用于引用 \end{ 
   table} 
  1. 设置表格列宽和线宽
  • 方式一
\begin{ 
   table}[h] \caption{ 
   An example table} \centering \begin{ 
   tabular}{ 
   ccc}{ 
   p{ 
   2cm}p{ 
   1.5cm}p{ 
   1.5cm}p{ 
   1.5cm}}%设置列宽 \toprule [1pt] % 设置表格线宽 Column 1 & Column 2 & Column 3 \\ \midrule Data 1 & Data 2 & Data 3 \\ Data 4 & Data 5 & Data 6 \\ Data 7 & Data 8 & Data 9 \\ \bottomrule \end{ 
   tabular} \label{ 
   tab:example} % 表格标签,用于引用 \end{ 
   table} 
  • 方式二
\begin{ 
   table}[h] \caption{ 
   An example table} \centering \setlength{ 
   \tabcolsep}{ 
   1.9mm}{ 
    %设置表格列宽 \begin{ 
   tabular}{ 
   ccc} \toprule [1pt] Column 1 & Column 2 & Column 3 \\ \midrule [1pt] Data 1 & Data 2 & Data 3 \\ Data 4 & Data 5 & Data 6 \\ Data 7 & Data 8 & Data 9 \\ \bottomrule [1pt] \end{ 
   tabular}} \label{ 
   tab:example} \end{ 
   table} 
  1. 设置表格间距
\begin{ 
   table}[h] \caption{ 
   An example table} \centering \Vspace{ 
   xxx} %设置表格与前文间的距离 \begin{ 
   tabular}{ 
   ccc}{ 
   p{ 
   2cm}p{ 
   1.5cm}p{ 
   1.5cm}p{ 
   1.5cm}}%设置列宽 \toprule [1pt] % 设置表格线宽 Column 1 & Column 2 & Column 3 \\ \midrule Data 1 & Data 2 & Data 3 \\ Data 4 & Data 5 & Data 6 \\ Data 7 & Data 8 & Data 9 \\ \bottomrule \end{ 
   tabular} \Vspace{ 
   xxx} %设置表格与后文间的距离 \label{ 
   tab:example} % 表格标签,用于引用 \end{ 
   table} 
  1. 复杂表格
  • 合并列的表格
\begin{ 
   table}[htbp] \centering \begin{ 
   tabular}{ 
   cccccc} \toprule \multicolumn{ 
   2}{ 
   c}{ 
   \textbf{ 
   Group 1}} & \multicolumn{ 
   2}{ 
   c}{ 
   \textbf{ 
   Group 2}} & \multicolumn{ 
   2}{ 
   c}{ 
   \textbf{ 
   Group 3}} \\ % 合并列作为组标题 \cmidrule(lr){ 
   1-2} \cmidrule(lr){ 
   3-4} \cmidrule(lr){ 
   5-6} \textbf{ 
   Sub 1} & \textbf{ 
   Sub 2} & \textbf{ 
   Sub 3} & \textbf{ 
   Sub 4} & \textbf{ 
   Sub 5} & \textbf{ 
   Sub 6} \\ \midrule Row 1 & Data 1 & Data 2 & Data 3 & Data 4 & Data 5 \\ Row 2 & Data 6 & Data 7 & Data 8 & Data 9 & Data 10 \\ Row 3 & \multicolumn{ 
   2}{ 
   c}{ 
   Merged Cell} & Data 11 & \multicolumn{ 
   2}{ 
   c}{ 
   Merged Cell} \\ % 合并列 Row 4 & Data 12 & Data 13 & Data 14 & Data 15 & Data 16 \\ \bottomrule \end{ 
   tabular} \caption{ 
   A Table with Merged Columns} \label{ 
   tab:merged_columns} \end{ 
   table} 
  • 合并行的表格
\begin{ 
   table}[htbp] \caption{ 
   An example table} \centering \begin{ 
   tabular}{ 
   p{ 
   30mm}p{ 
   35mm}p{ 
   40mm}} \toprule [1pt] Column 1 & Column 2 & Column 3 \\ \midrule [1pt] \multirow{ 
   5 }{ 
   =}{ 
   machine learning} & \multirow{ 
   1 }{ 
   =}{ 
   reference1} &\multirow{ 
   5 }{ 
   =}{ 
   advantage} \\ &\multirow{ 
   1}{ 
   =}{ 
   reference2} \\ & \multirow{ 
   1}{ 
   =}{ 
   reference3} \\ & \multirow{ 
   1}{ 
   =}{ 
   reference4} \\ & \multirow{ 
   1}{ 
   =}{ 
   reference5} \\ \multirow{ 
   3}{ 
   =}{ 
   deep learning} & \multirow{ 
   1}{ 
   =}{ 
   reference1} & \multirow{ 
   3}{ 
   =}{ 
   advantage} \\ & \multirow{ 
   1}{ 
   =}{ 
   reference2}\\ & \multirow{ 
   1}{ 
   =}{ 
   reference3}\\ \bottomrule [1pt] \end{ 
   tabular} \vspace{ 
   -2mm} \label { 
   tab:merged_rows} \end{ 
   table} 
  1. 双栏表格
    Latex中双栏排版时,要使表格占满双栏,使用如下代码
\begin{ 
   table*}[htbp] % 使用table*环境让表格跨越双栏 \caption{ 
   An example table spanning two columns} \centering \begin{ 
   tabular}{ 
   p{ 
   30mm}p{ 
   35mm}p{ 
   40mm}} \toprule[1pt] Column 1 & Column 2 & Column 3 \\ \midrule[1pt] \multirow{ 
   5}{ 
   =}{ 
   Machine Learning} & \multirow{ 
   1}{ 
   =}{ 
   Reference 1} & \multirow{ 
   5}{ 
   =}{ 
   Advantage} \\ & \multirow{ 
   1}{ 
   =}{ 
   Reference 2} \\ & \multirow{ 
   1}{ 
   =}{ 
   Reference 3} \\ & \multirow{ 
   1}{ 
   =}{ 
   Reference 4} \\ & \multirow{ 
   1}{ 
   =}{ 
   Reference 5} \\ \multirow{ 
   3}{ 
   =}{ 
   Deep Learning} & \multirow{ 
   1}{ 
   =}{ 
   Reference 1} & \multirow{ 
   3}{ 
   =}{ 
   Advantage} \\ & \multirow{ 
   1}{ 
   =}{ 
   Reference 2} \\ & \multirow{ 
   1}{ 
   =}{ 
   Reference 3} \\ \bottomrule[1pt] \end{ 
   tabular} \vspace{ 
   -2mm} \label{ 
   tab:merged_rows} \end{ 
   table*} 

免责声明:本站所有文章内容,图片,视频等均是来源于用户投稿和互联网及文摘转载整编而成,不代表本站观点,不承担相关法律责任。其著作权各归其原作者或其出版社所有。如发现本站有涉嫌抄袭侵权/违法违规的内容,侵犯到您的权益,请在线联系站长,一经查实,本站将立刻删除。 本文来自网络,若有侵权,请联系删除,如若转载,请注明出处:https://haidsoft.com/112641.html

(0)
上一篇 2026-01-16 22:15
下一篇 2026-01-16 22:26

相关推荐

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注微信