转载的,自己留着用到的时候查。原出处:http://blog.csdn.net/juechenyi/article/details/77116011
1.基本格式
\documentclass{article}
\begin{document}
\begin{tabular}{cc}
(1,1)&(1,2)\\
(2,1)&(2,2)\\
\end{tabular}
\end{document}
效果如下:
2.添加竖线和横线
\documentclass{article}
\begin{document}
\begin{tabular}{|c|c|}
\hline
(1,1)&(1,2)\\
\hline
(2,1)&(2,2)\\
\hline
\end{tabular}
\end{document}
效果如下:
3.设置每一列的单元格格式
\documentclass{article}
\begin{document}
\begin{tabular}{|l|c|r|}
\hline
Name&Steve&Bill\\
\hline
Matlab&Mathmatica&Maple\\
\hline
\end{tabular}
\end{document}
效果如下:
4.常见的三线表
\documentclass[UTF8]{ctexart}
\begin{document}
\begin{tabular}{ccc}
\hline
姓名& 学号& 性别\\
\hline
Steve Jobs& 001& Male\\
Bill Gates& 002& Female\\
\hline
\end{tabular}
\end{document}
效果如下:
通常来说,我们会希望表格的第一根线和最后一根线比表格中的横线更粗一些。
booktabs 宏包为我们提供了这个功能,加载 booktabs 宏包之后可以使用 \toprule 和 \bottomrule 命令分别画出表格头和表格底的粗横线,而用 \midrule 画出表格中的横线。
\documentclass[UTF8]{ctexart}
\usepackage{booktabs}
\begin{document}
\begin{tabular}{ccc}
\toprule
姓名& 学号& 性别\\
\midrule
Steve Jobs& 001& Male\\
Bill Gates& 002& Female\\
\bottomrule
\end{tabular}
\end{document}
效果如下:
5.table环境
\documentclass[UTF8]{ctexart}
\usepackage{booktabs}
\begin{document}
\begin{table}[!htbp]
\centering
\caption{这是一张三线表}\label{tab:aStrangeTable}
\begin{tabular}{ccc}
\toprule
姓名& 学号& 性别\\
\midrule
Steve Jobs& 001& Male\\
Bill Gates& 002& Female\\
\bottomrule
\end{tabular}
\end{table}
\end{document}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
{table}有若干可选参数 [!htbp]
h
代表here,将表格排在当前文字位置
t
表示将表格放在下一页的 top (页首)
b
表示将表格放在当前页的 bottom (底部)
!
表示忽略美观因素,尽可能按照参数指定的方式来处理表格浮动位置。
表格将会按照所给参数,依次尝试按照每个参数进行排版,当无法排版时,将会按照下一个参数
6.单元格合并
\documentclass[UTF8]{ctexart}
\begin{document}
\begin{table}[!htbp]
\centering
\begin{tabular}{|c|c|c|}
\hline
\multicolumn{3}{|c|}{学生信息}\\
\hline
姓名&学号&性别\\
\hline
Jack& 001& Male\\
\hline
Angela& 002& Female\\
\hline
\end{tabular}
\caption{这是一张三线表}
\end{table}
\end{document}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
效果如下:
\documentclass[UTF8]{ctexart}
\usepackage{multirow}
\begin{document}
\begin{table}[!htbp]
\centering
\begin{tabular}{|c|c|c|c|c|c|c|}
\hline
\multicolumn{7}{|c|}{事件}\\
\hline
\multirow{4}*{策略}&50&0&100&200&300&300\\
\cline{2-7}
&100&100&0&100&200&200\\
\cline{2-7}
&150&200&100&0&100&200\\
\cline{2-7}
&200&300&200&100&0&300\\
\hline
\end{tabular}
\end{table}
\end{document}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
横向合并和纵向合并可以嵌套,代码如下:
\documentclass[UTF8]{ctexart}
\usepackage{multirow}
\begin{document}
\begin{table}[!htbp]
\centering
\begin{tabular}{|c|c|c|c|c|c|c|}
\hline
\multicolumn{2}{|c|}{ \multirow{2}*{$S_i$} }& \multicolumn{4}{c|}{事件} &\multirow{2}*{max}\\
\cline{3-6}
\multicolumn{2}{|c|}{}&50&100&150&200&\\
\hline
\multirow{4}*{策略}&50&0&100&200&300&300\\
\cline{2-7}
&100&100&0&100&200&200\\
\cline{2-7}
&150&200&100&0&100&200\\
\cline{2-7}
&200&300&200&100&0&300\\
\hline
\end{tabular}
\end{table}
\end{document}
- 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
效果如下:
7.斜线表头
需要使用{diagbox}宏包
\documentclass{UTF8}{ctexart}
\usepackage{diagbox}
\begin{document}
\begin{table}[!htbp]
\centering
\begin{tabular}{|c|c|c|c|}
\hline
\diagbox{甲}{$\alpha_{i,j}$}{乙}&$\beta_1$&$\beta_2$&$\beta_3$\\
\hline
$\alpha_1$&-4&0&-8\\
\hline
$\alpha_2$&3&2&4\\
\hline
$\alpha_3$&16&1&-9\\
\hline
$\alpha_4$&-1&1&7\\
\hline
\end{tabular}
\end{table}
\end{document}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
效果如下: