LaTeX Tables

本文介绍了如何在LaTeX中使用Overleaf创建各种类型的表格,包括普通表格、带边线的表格、三线表、宽度控制(不等宽和等宽)、以及添加notes和调整字体大小。还提到了处理复杂表格时的注意事项。
摘要由CSDN通过智能技术生成

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表格生成的需要。

  • 21
    点赞
  • 17
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值