LaTeX 系列(4) —— Table

 接上一篇 LaTeX 系列(3) —— Figure,这篇文章介绍Latex中的各种Table样式和排版的实现。

1. 导入所需的包

全部导入就完事了:

\usepackage{booktabs}  % toprule, midrule, bottomrule
\usepackage{multirow}  % multirow, multicolumn
\usepackage{graphicx}  % resizebox
\usepackage{threeparttable}  % footnote
\usepackage{makecell}        % makecell

2. 不同表格样式

Latex代码:

% Table 1
\begin{table}[htbp]
    \centering
    \caption{Caption}
    \label{tab:my_label}
    \begin{tabular}{|c | ccccc|}
    \hline
    Letter & A & B & C & D & E\\
    \hline
    Number & 1 & 2 & 3 & 4 & 5\\
    \hline
    \end{tabular}
\end{table}

% Table 2
\begin{table}[htbp]
    \centering
    \caption{Caption}
    \label{tab:my_label}
    \begin{tabular}{c | ccccc}
    \hline\hline
    Letter & A & B & C & D & E\\
    \hline
    Number & 1 & 2 & 3 & 4 & 5\\
    \hline\hline
    \end{tabular}
\end{table}

% Table 3
\begin{table}[htbp]
    \centering
    \caption{Caption}
    \label{tab:my_label}
    \begin{tabular}{c ccccc}
    \toprule
    Letter & A & B & C & D & E\\
    \midrule
    Number & 1 & 2 & 3 & 4 & 5\\
    \bottomrule
    \end{tabular}
\end{table}

效果:

3. 表格尺寸调整

Latex代码:

\begin{table}[htbp]
\centering
\caption{Caption}
\label{tab:my_label}
\setlength{\tabcolsep}{5pt}        % 列间隔
\renewcommand{\arraystretch}{1.0}  % 行间隔
\resizebox{\textwidth}{!}{      % 调整整个表格的尺寸
    \begin{tabular}{|c ccccc|}
    \hline
    Letter & A & B & C & D & E\\
    \hline
    Number & 1 & 2 & 3 & 4 & 5\\
    \hline
    \end{tabular}
}
\end{table}

效果:

4. 多行合并,多列合并

Latex代码:

\begin{table}[htbp]
\centering
    \caption{Caption}
    \label{tab:my_label}
    \begin{tabular}{|c | ccccc|}
    \hline
    \multirow{2}{*}{Letter} & A & B & C & D & E\\
    ~ & F & G & H & I & J\\
    \hline
    \end{tabular}
\end{table}

\begin{table}[htbp]
\centering
    \caption{Caption}
    \label{tab:my_label}
    \begin{tabular}{|ccccc | ccccc|}
    \hline
    \multicolumn{5}{|c|}{Letter} & \multicolumn{5}{c|}{Number}\\
    \hline
    A & B & C & D & E & 1 & 2 & 3 & 4 & 5\\
    \hline
    \end{tabular}
\end{table}

效果:

5. 表格并排

Latex代码:

\begin{minipage}{0.5\textwidth}
\centering
\captionsetup{type=table}
\caption{Caption}
\begin{tabular}{|c | ccccc|}
\hline
Letter & A & B & C & D & E\\
\hline
Number & 1 & 2 & 3 & 4 & 5\\
\hline
\end{tabular}
~
\end{minipage}
\begin{minipage}{0.5\textwidth}
\centering
\captionsetup{type=table}
\caption{Caption}
\begin{tabular}{|c | ccccc|}
\hline
Letter & A & B & C & D & E\\
\hline
Number & 1 & 2 & 3 & 4 & 5\\
\hline
\end{tabular}
\end{minipage}

效果:

6. 特殊操作

Latex代码:

% 脚注
\begin{table}
\setlength{\belowcaptionskip}{2mm}
% \setlength{\abovecaptionskip}{2mm}
\centering
\caption{Table with footnotes after the table}
\begin{threeparttable}
    \begin{tabular}{|c | ccccc|}
    \hline
    Letter\tnote{$\dagger$} & A & B & C & D & E\\
    \hline
    Number & 1 & 2 & 3 & 4 & 5\\
    \hline
    \end{tabular}
    \begin{tablenotes}
    \item[$\dagger$] The letters are capital.
    \end{tablenotes}
\end{threeparttable}
\end{table}

% 单元格换行
\begin{table}[htbp]
\centering
    \caption{Caption}
    \label{tab:my_label}
    \begin{tabular}{|c | ccccc|}
    \hline
    \multirow{5}{*}{\makecell[c]{Capital\\Letters}} & A & B & C & D & E\\
    ~ & A & B & C & D & E\\
    ~ & A & B & C & D & E\\
    ~ & A & B & C & D & E\\
    ~ & A & B & C & D & E\\
    \hline
    \end{tabular}
\end{table}

效果:

### 如何在LaTeX中为表格添加注释 要在LaTeX中为表格添加注释,可以利用`threeparttable`宏包来实现更专业的效果。此方法允许将注释放置于表格下方并与其保持一致的宽度[^1]。 以下是具体实现方式的一个例子: #### 使用 `threeparttable` 宏包 通过引入`threeparttable`环境,可以在表格下方便地添加脚注样式的注释。这种方法不会影响整个文档页面布局,并能很好地管理表格中的额外说明文字。 ```latex \documentclass{article} \usepackage{booktabs} % 提供更好的表格线样式 \usepackage{threeparttable} % 支持表格内的注释功能 \begin{document} \begin{table}[h!] \centering \begin{threeparttable} \caption{Example Table with Notes} \label{tab:example_table_with_notes} \begin{tabular}{ccc} \toprule Column A & Column B & Column C \\ \midrule Value 1 & Value 2 & Value 3\tnote{*} \\ Value 4 & Value 5 & Value 6 \\ \bottomrule \end{tabular} \begin{tablenotes}\footnotesize \item[*] This is an example note explaining the starred value. \end{tablenotes} \end{threeparttable} \end{table} \end{document} ``` 上述代码展示了如何使用`\tnote{*}`标记特定单元格的内容以便稍后解释它,而实际的描述则放在`tablenotes`环境中定义。 如果遇到错误提示如“Extra alignment tab has been changed to \cr”,这通常意味着指定给列的数量与实际使用的数量不匹配,请检查表头部分是否有足够的`|c|`或其他类型的声明对应每一栏数据项[^2]。 另外需要注意的是,在调整图形或者表格整体居中显示时推荐采用`\centering`命令而非嵌套新的中心化环境(`\begin{center}`),这样有助于节省垂直空间从而优化排版效果[^3]。 最后提醒一点关于网络流量控制工具配置方面的小技巧:当操作涉及队列调度器(qdisc)及其内部类别(class)设置的时候,“tc class add”用于创建类目结构;相对应地,“tc qdisc add”则是用来向这些已存在的分类里附加具体的队列机制[^4]——虽然这条信息可能偏离当前主题较远但仍值得记住作为一般Linux系统管理员的知识补充。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值