墘青

LaTeX, Gaussian, ORCA and More...


  • 首页

  • 关于

  • 归档

  • 搜索

LaTeX中三线表、并置图片、固定表格

发表于 2019-07-15 更新于 2019-08-07 分类于 LaTeX

本文开始先和大家闲聊几句。之前的《从零开始的LaTeX教程》系列承蒙大家的照顾,阅读量还是很多的呢!甚至收到了不少打赏,开心!之后的文章我还是会采用GitHub Markdown的风格来排版,毕竟还算是有一点代码教学的嘛。

从这篇文章开始的《LaTeX使用技巧》系列会教大家应对一些在论文写作过程中比较常见的需求,让大家的LaTeX之旅更加顺利~

本文的主要内容:

  • 如何绘制论文需要的三线表
  • 如何并置多张图片
  • 如何不让图片和表格“乱跑”

画三线表

三线表是大家在写实验报告和论文的时候非常常见的表格样式。三线表通常只有三条线,即顶线、底线和栏目线,这三条线都是横线,表格中没有任何竖线。其中顶线和底线为粗线,栏目线为细线。

在LaTeX中实现三线表的效果非常简单。我们首先需要进入tabular环境,随后在对应的位置加入相应的横线:顶线是\toprule,栏目线是\midrule,底线是\bottomrule。下面是一个例子:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
\begin{tabular}{ccccc}
\toprule
Year & NME & New BLA & Total& Rate/\% \\
\midrule
2008 & 21 & 3 & 95 & 25.3 \\
2009 & 20 & 6 & 98 & 26.5 \\
2010 & 15 & 6 & 93 & 22.6 \\
2011 & 24 & 6 & 100 & 30 \\
2012 & 33 & 6 & 101 & 38.6 \\
2013 & 25 & 4 & 102 & 28.4 \\
2014 & 30 & 11 & 119 & 34.4 \\
2015 & 33 & 12 & 127 & 35.4 \\
2016 & 15 & 7 & 102 & 21.6 \\
2017 & 34 & 12 & 150 & 30.7 \\
2018 & 42 & 17 & 151 & 39.1 \\
\bottomrule
\end{tabular}

下面是这个例子的输出效果:

当然,一张完整的表格是需要标题和注释的。这一点需要在table环境中实现。我们可以用\caption{·}命令来为表格添加标题,以及用\label{·}命令添加标签以方便交叉引用。

但是为表格添加脚注是一件LaTeX经典难题。在脚注不太多的情况下我们可以手动在表格下面硬编码一条脚注。下面是一个例子:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
\begin{table}[htbp]
\centering
\caption{2008-2018年FDA审核通过的NME,BLA,NDA及创新药比例}
\begin{tabular}{ccccc}
\toprule
Year & NME & New BLA & Total*& Rate/\% \\
\midrule
2008 & 21 & 3 & 95 & 25.3 \\
2009 & 20 & 6 & 98 & 26.5 \\
2010 & 15 & 6 & 93 & 22.6 \\
2011 & 24 & 6 & 100 & 30 \\
2012 & 33 & 6 & 101 & 38.6 \\
2013 & 25 & 4 & 102 & 28.4 \\
2014 & 30 & 11 & 119 & 34.4 \\
2015 & 33 & 12 & 127 & 35.4 \\
2016 & 15 & 7 & 102 & 21.6 \\
2017 & 34 & 12 & 150 & 30.7 \\
2018 & 42 & 17 & 151 & 39.1 \\
\bottomrule
\end{tabular}

\footnotesize{*注:表中Total一栏指NDA+BLA的数量。}
\label{tab:table1}
\end{table}

下面是这个例子的输出效果:

在脚注比较多的时候,就可以使用来自tablefootnote宏包的\tablefootnote{·}命令来生成显示在表格下面的脚注。

并置多张图片

并置多张图片是我在写植物组织培养的实验报告的时候才第一次遇到的需求。不论是在论文、简历、PPT还是实验报告中,你都会常常遇到这种需求。在Microsoft Word里这个问题似乎看起来非常容易解决,但是在LaTeX里,解决方法就没有那么显然了。(当然,在你走头无路的时候总是能用Adobe Photoshop解决一切!大家想学PS的话,推荐大家关注公众号“HF的树洞”!)

在LaTeX中实现多张图片并置其实也不难。我们只需要用subfigure宏包提供的\subfigure[name-of-subfigure]{include-figure-file}命令即可。

大家可能要问了,如果有很多张图片不仅仅需要放一行该怎么办?LaTeX是非常奇妙的,我们只需要想输入文本时一样,打两个换行符或者用\\就可以了。下面是实战例子:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
\begin{figure}
\centering
\subfigure[Week 1-$t_0$]{\includegraphics[width=0.22\linewidth]{week1t0}}
\subfigure[Week 1-$t_1$]{\includegraphics[width=0.22\linewidth]{week1t1}}
\subfigure[Week 1-$t_2$]{\includegraphics[width=0.22\linewidth]{week1t2}}
\subfigure[Week 1-$t_3$]{\includegraphics[width=0.22\linewidth]{week1t3}}
\\
\subfigure[Week 2-$t_0$]{\includegraphics[width=0.22\linewidth]{week2t0}}
\subfigure[Week 2-$t_1$]{\includegraphics[width=0.22\linewidth]{week2t1}}
\subfigure[Week 2-$t_2$]{\includegraphics[width=0.22\linewidth]{week2t2}}
\subfigure[Week 2-$t_3$]{\includegraphics[width=0.22\linewidth]{week2t3}}
\\
\subfigure[Week 3-$t_0$]{\includegraphics[width=0.22\linewidth]{week3t0}}
\subfigure[Week 3-$t_1$]{\includegraphics[width=0.22\linewidth]{week3t1}}
\subfigure[Week 3-$t_2$]{\includegraphics[width=0.22\linewidth]{week3t2}}
\subfigure[Week 3-$t_3$]{\includegraphics[width=0.22\linewidth]{week3t3}}
\\
\subfigure[Week 4-$t_0$]{\includegraphics[width=0.22\linewidth]{week4t0}}
\subfigure[Week 4-$t_1$]{\includegraphics[width=0.22\linewidth]{week4t1}}
\subfigure[Week 4-$t_2$]{\includegraphics[width=0.22\linewidth]{week4t2}}
\subfigure[Week 4-$t_3$]{\includegraphics[width=0.22\linewidth]{week4t3}}
\\
\subfigure[Week 5-$t_0$]{\includegraphics[width=0.22\linewidth]{week5t0}}
\subfigure[Week 5-$t_1$]{\includegraphics[width=0.22\linewidth]{week5t1}}
\subfigure[Week 5-$t_2$]{\includegraphics[width=0.22\linewidth]{week5t2}}
\subfigure[Week 5-$t_3$]{\includegraphics[width=0.22\linewidth]{week5t3}}
\caption{植物生长调节剂诱导烟草叶片器官分化结果}
\label{fig:1}
\end{figure}

下面是这个例子的输出效果:

“固定”你的图片和表格

如果有试过排版有多张图片或者表格的小伙伴一定有过这样的疑惑:图片和表格怎么老是乱跑呢?到底怎么做才能固定住我的表格在我想要的位置呢?

其实,LaTeX原生支持对于浮动体位置的某种程度上的设置。在\begin{figure}后面我们可以加上类似[htbp]或者[tp]这样的参数。其中每一个字母都代表不同的位置:h代表“这里”;t代表页面最上端;b代表页面最底端;p代表下一页。

当你问出“我的图片怎么老是乱跑?”这个问题时,大部分情况下你是希望图片老老实实呆在你安插的文字中间。这个时候,我们可以结合float宏包提供的[H](注意这里是大写的)选项来禁用浮动。下面是一个例子:

1
2
3
4
5
6
7
8
9
10
The routine way to name compounds with heteroatoms can be identically to the naming of spiro compounds, like what is shown in Figure \ref{fig:7-azaspiro4}. In addition, unsaturation is also indicated in the traditional way.

\begin{figure}[H]
\centering
\includegraphics[width=0.5\linewidth]{7-azaspiro45dec-2-ene}
\caption{The conventional way to name heteroatoms and unsaturation is still available.}
\label{fig:7-azaspiro4}
\end{figure}

If a choice of nomenclature or numbering occurs because of heteroatoms, functional groups or substituents the following criteria are considered in order until a decision is made.

下面是这个例子的输出效果:

任之 wechat
订阅公众号以获取最新内容!
LaTeX绘制化学结构式
在LaTeX里处理引用
  • 文章目录
  • 站点概览
任之

任之

Personal blog featuring tutorials for LaTeX, Gaussian and ORCA in Chinese.
32 日志
4 分类
4 标签
GitHub E-Mail
  1. 1. 画三线表
  2. 2. 并置多张图片
  3. 3. “固定”你的图片和表格
© 2020 任之
Alexander Qi 专属
|
闲言碎语