LaTeX 表格
本系列文章由 @YhL_Leo 出品,转载请注明出处。
文章链接: http://blog.csdn.net/yhl_leo/article/details/50066137
一些LaTeX中表格的使用方法如下:
1.table
\documentclass{article}
\begin{document}
\begin{table}[h]
\centering
\begin{tabular}{|l|c|c|}\hline
Setting&\multicolumn{2}{c|}{A4 size paper}\\\hline
&mm&inches\\
Top&25&1.0\\
Bottom&25&1.0\\
Left&20&0.8\\
Right&20&0.8\\
Column Width&82&3.2\\
Column Spacing&6&0.25\\\hline
\end{tabular}
\caption{Margin settings for A4 size paper}
\label{tab:Margin_settings}
\end{table}
\end{document}
2.tabular
\begin{tabular}{|c|c|c|}
\hline 2&9&4\\
\hline 7&5&3\\
\hline 6&1&8\\
\hline
\end{tabular}
例子里面的|c|
这样的,那个地方叫做导言区,来约定表格的每列属性的:
l |
left-justified column |
c |
centered column |
r |
right-justified column |
b |
bottom |
c |
center (default) |
t |
top |
p{'width'} |
paragraph column with text vertically aligned at the top |
m{'width'} |
paragraph column with text vertically aligned in the middle (requires array package) |
b{'width'} |
paragraph column with text vertically aligned at the bottom (requires array package) |
| |
vertical line |
|| |
double vertical line |
另外,还有一些常用的命令:
& |
column separator |
\\ |
start new row (additional space may be specified after \\ using square brackets, such as \\[6pt] |
\hline |
horizontal line |
\newline |
start a new line within a cell (in a paragraph column) |
\tabularnewline |
start a new line within a cell (in a paragraph column) instead of \\ to avoid a Misplaced \noalign error in the tabular |
\cline{i-j} |
partial horizontal line beginning in column i and ending in column j |
除了最简单的用例外,还可以这样:
% example 1:
\begin{center}
\begin{tabular}{ | l || c || r }
\hline
1 & 2 & 3 \\ \hline
4 & 5 & 6 \\ \hline \hline
7 & 8 & 9 \\
\hline
\end{tabular}
\end{center}
example 1
% example 2:
%\multicolumn{n}{format}{item}
\begin{tabular}{|c|c|c|}
\hline \multicolumn{3}{|c|}{?}\\
\hline 7&5&3\\
\hline 6&1&8\\
\hline
\end{tabular}
example 2
% example 3:
\begin{tabular}{|r|l|}
\hline
7C0 & hexadecimal \\
3700 & octal \\ \cline{2-2}
11111000000 & binary \\
\hline \hline
1984 & decimal \\
\hline
\end{tabular}
example 3
在array
环境中(使用时需要包含:\usepackage{array}
),重新实现了tabular环境,加了不少新选项进去:
对于tabular
的第一个例子略作修改,可以发现在不含有array
包和含有时效果是不一样的:
% example 1:
%\usepackage{array}
\tabcolsep20pt
\arrayrulewidth2pt
\begin{tabular}{*{3}{|c}|}
%\begin{tabular}{|c|c|c|}
\hline 2&9&4\\
\hline 7&5&3\\
\hline 6&1&8\\
\hline
\end{tabular}
% example 2:
...
\usepackage{array}
...
\tabcolsep20pt
\arrayrulewidth2pt
\begin{tabular}{*{3}{|c}|}
%\begin{tabular}{|c|c|c|}
\hline 2&9&4\\
\hline 7&5&3\\
\hline 6&1&8\\
\hline
\end{tabular}
example 1
example 2
对于表格内有长文本时,直接排下来不但很难看而且很容超出页面的范围,可以这么做:
Without specifying width for last column:
\begin{center}
\begin{tabular}{| l | l | l | l |}
\hline
Day & Min Temp & Max Temp & Summary \\ \hline
Monday & 11C & 22C & A clear day with lots of sunshine.
However, the strong breeze will bring down the temperatures. \\ \hline
Tuesday & 9C & 19C & Cloudy with rain, across many northern regions. Clear spells
across most of Scotland and Northern Ireland,
but rain reaching the far northwest. \\ \hline
Wednesday & 10C & 21C & Rain will still linger for the morning.
Conditions will improve by early afternoon and continue
throughout the evening. \\
\hline
\end{tabular}
\end{center}
With width specified:
\begin{center}
\begin{tabular}{ | l | l | l | p{5cm} |}
\hline
Day & Min Temp & Max Temp & Summary \\ \hline
Monday & 11C & 22C & A clear day with lots of sunshine.
However, the strong breeze will bring down the temperatures. \\ \hline
Tuesday & 9C & 19C & Cloudy with rain, across many northern regions. Clear spells
across most of Scotland and Northern Ireland,
but rain reaching the far northwest. \\ \hline
Wednesday & 10C & 21C & Rain will still linger for the morning.
Conditions will improve by early afternoon and continue
throughout the evening. \\
\hline
\end{tabular}
\end{center}
另外使用宏包tabulary
也可以实现:
\usepackage{tabulary}
...
\begin{center}
\begin{tabulary}{0.7\textwidth}{LCL}
Short sentences & \# & Long sentences \\
\hline
This is short. & 173 & This is much loooooooonger, because there are many more words. \\
This is not shorter. & 317 & This is still loooooooonger, because there are many more words. \\
\end{tabulary}
\end{center}
其中的对齐方式除了L
,C
外,还有R
,J
。
让我们看下\parbox
的用法,如果我们想把文段分割成为表的形式:
\begin{tabular}{cc}
boring cell content & \parbox[t]{5cm}{rather long par\\new par}
\end{tabular}
调整行列间距可以使用命令:
\setlength{\tabcolsep}{5pt} %colums, default value is 6pt
\renewcommand{\arraystretch}{1.5} %rows, default value is 1.0
另外一种方式是在\hline
和cline{i-j}
后添加\noalign{\smallskip}
, 例如:
\begin{center}
\begin{tabular}{ | l | l | r | }
\hline
\multicolumn{2}{c}{Item} \\
\cline{1-2}
Animal & Description & Price (\$) \\
\hline
Gnat & per gram & 13.65 \\
& each & 0.01 \\
Gnu & stuffed & 92.50 \\
Emu & stuffed & 33.33 \\
Armadillo & frozen & 8.99 \\
\hline
\end{tabular}
example 1
$ $
\setlength{\tabcolsep}{4pt}
\begin{tabular}{ | l | l | r | }
\hline
\multicolumn{2}{c}{Item} \\
\cline{1-2}
Animal & Description & Price (\$) \\
\hline
Gnat & per gram & 13.65 \\
& each & 0.01 \\
Gnu & stuffed & 92.50 \\
Emu & stuffed & 33.33 \\
Armadillo & frozen & 8.99 \\
\hline
\end{tabular}
example 2
$ $
\renewcommand{\arraystretch}{1.5}
\begin{tabular}{ | l | l | r | }
\hline
\multicolumn{2}{c}{Item} \\
\cline{1-2}
Animal & Description & Price (\$) \\
\hline
Gnat & per gram & 13.65 \\
& each & 0.01 \\
Gnu & stuffed & 92.50 \\
Emu & stuffed & 33.33 \\
Armadillo & frozen & 8.99 \\
\hline
\end{tabular}
example 3
$ $
\setlength{\tabcolsep}{6pt}
\renewcommand{\arraystretch}{1.0}
\begin{tabular}{ | l | l | r | }
\hline\noalign{\smallskip}
\multicolumn{2}{c}{Item} \\
\cline{1-2}\noalign{\smallskip}
Animal & Description & Price (\$) \\
\noalign{\smallskip}\hline\noalign{\smallskip}
Gnat & per gram & 13.65 \\
& each & 0.01 \\
Gnu & stuffed & 92.50 \\
Emu & stuffed & 33.33 \\
Armadillo & frozen & 8.99 \\
\noalign{\smallskip}\hline
\end{tabular}
example 4
\end{center}
其他用法如在某一行后空出一定间距:
\begin{tabular}{ll}
\hline
Mineral & Color \\[0.5cm]
Ruby & red \\
Sapphire & blue \\
\hline
\end{tabular}
一些LaTeX的环境也可以插入表格中:
\begin{tabular}{m{5cm} c} % here the m can be replaced by p or b.
\\ \hline
\begin{verbatim}
I love coding
\end{verbatim}
& LaTeX
\\ \hline
\end{tabular}
使用列规格设置命令:>{\cmd} and <{\cmd}
,如设置表格中的字符都是数学手写字体:
...
\usepackage{array}
...
\newcolumntype{F}{>{$}c<{$}}
\begin{tabular}{FFF}
\alpha & \beta & \gamma \\
\delta & \epsilon & \upsilon \\
\sigma & \tau & \phi \\
\end{tabular}
@-expressions的用法:
\begin{tabular}{|@{}l|l@{}|}
\hline
stuff & stuff \\ \hline
stuff & stuff \\
\hline
\end{tabular}
\begin{tabular}{r@{.}l}
3 & 14159 \\
16 & 2 \\
123 & 456 \\
\end{tabular}
行的特别设置,给出几个例子:
\begin{tabular}{ |l|l| }
\hline
\multicolumn{2}{|c|}{Team sheet} \\
\hline
GK & Paul Robinson \\
LB & Lucas Radebe \\
DC & Michael Duberry \\
DC & Dominic Matteo \\
RB & Dider Domi \\
MC & David Batty \\
MC & Eirik Bakke \\
MC & Jody Morris \\
FW & Jamie McMaster \\
ST & Alan Smith \\
ST & Mark Viduka \\
\hline
\end{tabular}
...
\usepackage{multirow}
...
\begin{tabular}{ |l|l|l| }
\hline
\multicolumn{3}{ |c| }{Team sheet} \\
\hline
Goalkeeper & GK & Paul Robinson \\ \hline
\multirow{4}{*}{Defenders} & LB & Lucas Radebe \\
& DC & Michael Duburry \\
& DC & Dominic Matteo \\
& RB & Didier Domi \\ \hline
\multirow{3}{*}{Midfielders} & MC & David Batty \\
& MC & Eirik Bakke \\
& MC & Jody Morris \\ \hline
Forward & FW & Jamie McMaster \\ \hline
\multirow{2}{*}{Strikers} & ST & Alan Smith \\
& ST & Mark Viduka \\
\hline
\end{tabular}
...
\usepackage{multirow}
...
\begin{tabular}{cc|c|c|c|c|l}
\cline{3-6}
& & \multicolumn{4}{ c| }{Primes} \\ \cline{3-6}
& & 2 & 3 & 5 & 7 \\ \cline{1-6}
\multicolumn{1}{ |c }{\multirow{2}{*}{Powers} } &
\multicolumn{1}{ |c| }{504} & 3 & 2 & 0 & 1 & \\ \cline{2-6}
\multicolumn{1}{ |c }{} &
\multicolumn{1}{ |c| }{540} & 2 & 3 & 1 & 0 & \\ \cline{1-6}
\multicolumn{1}{ |c }{\multirow{2}{*}{Powers} } &
\multicolumn{1}{ |c| }{gcd} & 2 & 2 & 0 & 0 & min \\ \cline{2-6}
\multicolumn{1}{ |c }{} &
\multicolumn{1}{ |c| }{lcm} & 3 & 3 & 1 & 1 & max \\ \cline{1-6}
\end{tabular}
\begin{tabular}{ r|c|c| }
\multicolumn{1}{r}{}
& \multicolumn{1}{c}{noninteractive}
& \multicolumn{1}{c}{interactive} \\
\cline{2-3}
massively multiple & Library & University \\
\cline{2-3}
one-to-one & Book & Tutor \\
\cline{2-3}
\end{tabular}
3.booktabs
即三线表:
\usepackage{booktabs}
\begin{tabular}{ccc}
\toprule
2&9&4\\
\midrule
7&5&3\\
6&1&8\\
\bottomrule
\end{tabular}
4.colortbl
常用的表格填色colortbl
包:
% example 1:
\usepackage{colortbl}
\begin{tabular}{ccc}
\rowcolor[gray]{.9}
2&9&4\\
\rowcolor[gray]{.8}
7&5&3\\
\rowcolor[gray]{.7}
6&1&8\\
\end{tabular}
example 1
% example 2:
\begin{tabular}
{>{\columncolor[gray]{.9}}c|
>{\columncolor[gray]{.8}}c|
>{\columncolor[gray]{.7}}c}
2&9&4\\
7&5&3\\
6&1&8\\
\end{tabular}
example 2
%example 3:
\begin{tabular}{ccc}
\cellcolor[rgb]{.9,.9,.9}2&
\cellcolor[rgb]{.8,.9,.9}9&
\cellcolor[rgb]{.7,.9,.9}4\\
\cellcolor[rgb]{.9,.8,.9}7&
\cellcolor[rgb]{.8,.8,.9}5&
\cellcolor[rgb]{.7,.8,.9}3\\
\cellcolor[rgb]{.9,.7,.9}6&
\cellcolor[rgb]{.8,.7,.9}1&
\cellcolor[rgb]{.7,.7,.9}8\\
\end{tabular}
example 3
5.diagbox
画斜线表头的包diagbox
\usepackage{diagbox}
...
\begin{tabular}{|l|ccc|}
\hline
\diagbox{Time}{Room}{Day} & Mon & Tue & Wed \\
\hline
Morning & used & used & \\
Afternoon & & used & used \\
\hline
\end{tabular}
参考:
LaTeX 表格的更多相关文章
- Latex 表格内公式换行方法
Latex 表格内的公式实现换行的方法 简单的两步走: 1.先将下面的语句放在latex正文的导言区: \newcommand{\tabincell}[2]{\begin{tabula ...
- LaTeX 表格指定宽度并居中
本系列文章由 @YhL_Leo 出品,转载请注明出处. 文章链接: http://blog.csdn.net/yhl_leo/article/details/50532269 在绘制表格的时候,对于特 ...
- Latex表格制作记录
Latex表格制作记录 主要功能 合并表格的行列 长表格的使用 makecell例程借鉴 效果图 参考代码 \documentclass{ctexart} \usepackage{indentfirs ...
- 加粗合并latex表格线的加粗及合并两行
每日一贴,今天的内容关键字为加粗合并 在latex中要设置加粗的表格线,要使用如下包: \usepackage{booktabs} 如下图中的表格,首行(\toprule[2pt]),旁边行(\mid ...
- Latex 表格内文字过长自动换行
法一: [plain] view plaincopy \begin{tabular}{m{5cm}} 法二: [plain] view plaincopy \begin{tabular}{p{0.9\ ...
- Latex(表格|图片(一丢丢))
目录 普通的例子 Notation 例子 p{width} 列分割符 @{} \multicolumn supertabular | longtabular 浮动体 table 浮动体 图片 \use ...
- latex表格代码
基本代码 \begin{table}[!h] \caption{Notations Used in Real-time Analysis.} \label{table:notation} \cent ...
- LaTeX表格绘制备忘之Go语言中的几个表
以下绘制的表格选自<Go语言 云动力>一书.这些表格比较简单,LaTeX语句也比较简单. 完整代码: % 博客园陆巍的博客 https://www.cnblogs.com/atth ...
- LaTex: 表格单元格内容 分行显示/换行
问题:如何同时让表格同一行一个单元格的文字能垂直居中?比如说文字超长超出页面范围需要分行显示 答:(来源于smth) 方案一: \newcommand{\tabincell}[2]{\begin{ta ...
随机推荐
- BZOJ 2260 商店购物(最小树形图)
不会最小树形图的出门左转 其实如果确定每种商品第一件的购买顺序,那么剩下的商品肯定是以最优惠价格购买的. 如何确定各种商品第一件购买时的最小价值呢? 考虑如果购买了\(a_i\)这种商品,那么就能以\ ...
- [USACO18OPEN] Multiplayer Moo (并查集+维护并查集技巧)
题目大意:给你一个N*N的棋盘,棋盘上每个点都有一个权值 第一问求一个权值形成的最大联通块中点的数量 第一问求两个权值共同形成的最大联通块中点的数量 提供一种并查集的做法:(感谢大佬们的题解)第一问把 ...
- 2019-03-21 Python Request InsecureRequestWarning
问题: 使用Python3 requests发送HTTPS请求,已经关闭认证(verify=False)情况下,控制台会输出以下错误: InsecureRequestWarning: Unverifi ...
- H5知识点
一.总体变化 1.H5文档结构 <!DOCTYPE html> <html> <head> <title> 这是标题 </title> ...
- 【【henuacm2016级暑期训练】动态规划专题 I】Gargari and Permutations
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 注意这k个序列每个都是排列. 如果在每个序列中都满足y出现在x之后的话. 那么我们从x连一条有向边至y (有一个序列不满足就不连 ( ...
- Java基础学习总结(58)——JAVA堆、栈详解
关于堆栈的内容网上已经有很多资料了,这是我找的加上自己理解的一篇说明文: 一.内存区域类型 1.寄存器:最快的存储区, 由编译器根据需求进行分配,我们在程序中无法控制: 1. 栈:存放基本类型的变量数 ...
- [terry笔记]python购物程序
如下是一个购物程序: 先输入工资,显示商品列表,购买,quit退出,最后格式化输出所买的商品. count = 0 while True: #做一个循环判断,如果输入的不是数字,基于提示,三次后退出 ...
- HDU 4324 Contest 3
直接DFS即可 #include <iostream> #include <string.h> #include <algorithm> #include < ...
- HDU 1131
N个节点的不同的树的数目.这样 随便取一个节点作为根,那么他左边和右边的儿子节点个数就确定了,假定根节点标号为x,那么左子树的标号就从1到x-1,共x-1个,右子树的标号就从x+1到n,共n-x个,那 ...
- 数组溢界地址的正确使用: 即 int a[6] 中的 a[-1] 和 a[6] 正确使用
正如大家所知道的那样: 数组 int a[6] , 编译器阅读到这句数组定义,会为分配6个int 类型的地址:a[0] a[1] a[2] a[3] a[4] a[5].我们 能够正 ...