LaTeX Tables

LaTeX表格

最近使用Elsevier的LaTeX模板进行论文排版,在B站简单的学习了下,生成表格时遇到好些问题,花时间了解了下,简单记录一下,感觉有好多想写的,真正开始记录的时候感觉又没什么写的,文笔有限,敬请见谅(狗头/狗头/狗头)。

表格创建

推荐使用Overleaf作为LaTeX的编辑器,简单表格通过Overleaf自带表格添加功能即可实现。
复杂表格创建,可复制数据到Tables Generator中自动生成表格LaTeX表达式。
在这里插入图片描述

普通表格创建

表格创建需要用到\usepackage{graphicx},导入graphicx包,标准格式为:

\begin{table}
    \centering
    \begin{tabular}{ccc}
      1  & 2 & 3 \\
      4  & 5 & 6 \\
      7  & 8 & 9 \\
    \end{tabular}
    \caption{This is a Table}
    \label{tab:my_label}
\end{table}

在这里插入图片描述

生成具有边线的表格,通过加入 \hline(横线) 和 | (竖线)即可实现。

\begin{table}
    \centering
    \begin{tabular}{|c|c|c|}\hline
      1  & 2 & 3 \\ \hline
      4  & 5 & 6 \\ \hline
      7  & 8 & 9 \\ \hline
    \end{tabular}
    \caption{This is a Table}
    \label{tab:my_label}
\end{table}

在这里插入图片描述

三线表创建

三线表需要使用\usepackage{booktabs}命令,导入booktabs包,分别在第一行和最后一行加入\toprule \midrule \bottomrule添加相应的线段。

\begin{table}
\centering
\begin{tabular}{c c c}
    \toprule
    1 & 2 & 3 \\ \midrule
    4 & 5 & 6 \\
    7 & 8 & 9 \\ \bottomrule
    \end{tabular}
\caption{This is  a table}
\label{tab:my-table}
\end{table}

在这里插入图片描述

表格宽度控制

不等宽度表格

等宽度表格的创建需要使用\usepackage{array},导入array包,生成指定宽度的表格(每列表格的宽度可不同),表格内容默认居左显示,表达式如下:

\begin{table}
\centering
    \begin{tabular}{ | m{2cm} | m{2cm}| m{2cm} | } 
          \hline
          1 & 2 & 3 \\  \hline
          4 & 5 & 6 \\  \hline
          7 & 8 & 9 \\  \hline
    \end{tabular}
\caption{This is  a table}
\label{tab:my-table}
\end{table}

在这里插入图片描述
通过\resizebox{}命令,可指定基于文本内容宽度的表格。

\begin{table}
\centering
    \resizebox{\textwidth}{!}{
    \begin{tabular}{ | m{2cm} | m{2cm}| m{2cm} | } 
          \hline
          1 & 2 & 3 \\  \hline
          4 & 5 & 6 \\  \hline
          7 & 8 & 9 \\  \hline
    \end{tabular}
    }
\caption{This is  a table}
\label{tab:my-table}
\end{table}

在这里插入图片描述

可在\textwidth前指定宽度系数改变表格宽度。

\begin{table}
\centering
    \resizebox{0.5\textwidth}{!}{
    \begin{tabular}{ | m{2cm} | m{2cm}| m{2cm} | } 
          \hline
          1 & 2 & 3 \\  \hline
          4 & 5 & 6 \\  \hline
          7 & 8 & 9 \\  \hline
    \end{tabular}
    }
\caption{This is  a table}
\label{tab:my-table}
\end{table}

等宽度表格

使用\usepackage{tabularx},导入tabularx包,可创建等宽度大小的表格。

\begin{table}
\centering
    \begin{tabularx}{0.8\textwidth}{ 
        | >{\centering\arraybackslash}X
        | >{\centering\arraybackslash}X
        | >{\centering\arraybackslash}X | }
          \hline
          1 & 2 & 3 \\  \hline
          4 & 5 & 6 \\  \hline
          7 & 8 & 9 \\  \hline
    \end{tabularx}
\caption{This is  a table}
\label{tab:my-table}
\end{table}

在这里插入图片描述

表格底部notes添加

注意,使用Tables Generator生成的复杂表格,当在其下方加入notes时,可能出现宽度不一致的现象,需要对自动生成的表格进行一定的修改,方可实现notes的正确添加。

notes的添加需要导入threeparttable包,\usepackage{threeparttable},表达式如下所示,在下图所示位置添加对应的命令即可实现。

\begin{table*}[]
% \small
\centering
\caption{Test table in latex}
\label{tab:my-table4}
\begin{threeparttable}[b]
% \begin{tabular}{|m{1cm}|m{1cm}|m{1cm}|m{1cm}|m{1cm}|}
\begin{tabularx}{0.7\textwidth}{
>{\centering\arraybackslash}X
>{\centering\arraybackslash}X
>{\centering\arraybackslash}X
>{\centering\arraybackslash}X
>{\centering\arraybackslash}X}
\toprule
row/col & col1 & col1 & col1 & col1 \\ \midrule
row1    & 1    & 2    & 3    & 4    \\ 
row1    & 1    & 2    & 3    & 4    \\ 
row1    & 1    & 2    & 3    & 4    \\ 
row1    & 1    & 2    & 3    & 4    \\ \bottomrule
\end{tabularx}
\begin{tablenotes}[normal,flushleft]
\item[1] In this study, our aim was to address three aspects of face mask wearing—public policies, individual behaviors and attitudes, and the collective experiences of the affected communities. 
\item[2] In this study, our aim was to address three aspects of face mask wearing—public policies, individual behaviors and attitudes, and the collective experiences of the affected communities. 
\end{tablenotes}
\end{threeparttable}
\end{table*}

论文中排版效果如上所示

在这里插入图片描述

表格字体大小控制

LaTeX中字体大小由小到大依次为:
\tiny
\scriptsize
\footnotesize
\small
\normalsize
\large
\Large
\LARGE
\huge
\Huge
控制表格中字体大小,只需要在表格后加入以上表达式即可

\begin{table}
\small(表示大小的命令)

总结

将以上提到的命令进行简单组合,即可实现一般论文中LaTeX表格生成的需要。

### 创建和编辑LaTeX表格的方法 在LaTeX中创建和编辑表格可以通过多种方式实现。一种便捷的方式是利用在线工具来辅助构建复杂的表格结构。 #### 使用在线LaTeX表格编辑器 为了简化表格的创建过程,可以借助于专门设计用于此目的的网站,比如LaTeX Tables Editor (latex-tables.com)[^1] 和 TablesGenerator.com[^2] 提供了直观界面让用户能够轻松地调整行列以及应用样式而无需手动编写冗长的代码片段。 #### 手动编写LaTeX表格命令 对于更高级的需求或者偏好直接编码的情况,则可以直接通过LaTeX语法定义表格: - **基本框架** 下面是一个简单的例子展示了如何建立一个基础版本的表格: ```tex \begin{tabular}{|l|r|} \hline Left aligned & Right Aligned \\ Item A & Value B \\ Item C & Value D \\ \hline \end{tabular} ``` - **添加标题** 给定的资料提到可以在`table`环境中加入`\caption{}`指令为整个表格加上描述性的标题,并且还可以使用`\label{}`为其分配唯一标识符以便后续引用[^3]: ```tex \begin{table}[htbp] \centering \caption{My Table Title}\label{my_table_label} % ... table content ... \end{table} ``` - **处理复杂布局** 当遇到需要跨越多个单元格的情形时,可采用特定命令如`\multicolumn{}{}{}` 或者 `\multirow{}{}{}` 来完成跨列或跨行的操作[^4]: ```tex \usepackage{multirow} % 需要先引入宏包 \begin{tabular}{cc} \multicolumn{2}{c}{Header Spanning Two Columns}\\ Column One & Column Two\\ \multirow{2}{*}{Row spanning two rows}& Entry one\\ & Entry two\\ \end{tabular} ``` 这些资源和技术可以帮助有效地管理和美化文档中的表格部分,在学术写作和其他正式出版物准备过程中发挥重要作用。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值