较复杂表格——行列合并
注意:需要导入的宏包 \usepackage{multirow}
\begin{tabular}{|c|c|c|c|c|}
\hline
%跨行(将两行合并为一行) 第一个参数指明跨几行 记得下一行对应位置空出来 不然会重叠
\multirow{2}{*}{1} & 11 & 111 & 1111 & 11111 \\
\cline{2-5}
& 22 & 222 & 2222 & 22222 \\
\hline
3 & 33 & 333 & 3333 & 33333 \\
\hline
\end{tabular}
\begin{tabular}{|c|c|c|c|c|}
\hline
% after \\: \hline or \cline{col1-col2} \cline{col3-col4} ...
%跨列(将两列合并为一列)第一个参数指明跨几列 第二个参数指明内容居中并在左右两边画上直线 最后一个参数是表格内容
\multicolumn{2}{|c|}{1} & 111 & 1111 & 11111 \\
\hline
2 & 22 & 222 & 2222 & 22222 \\
\hline
3 & 33 & 333 & 3333 & 33333 \\
\hline
\end{tabular}
结果如下:
四种指令简略说明
\multirow{2}{*}{表格内容}
\multirow是跨行功能,第一个参数2,表示跨两行,第二个参数*,表示系统自动调整文字,最后一个参数即是要填入的文字。跨列需注意的是,使用\multirow指令的那一列表格,到了要撰写下一列表格时,被跨列直接留空,不可填字
\multicolumn{2}{c|}{表格内容}
\multicolumn是跨列功能,第一个参数2,表示跨两列,第二个参数c|,表示文字置中,并在栏位右边画一条直线框,最后一个参数即是要填入的文字
\hline 表示画出一整条从左至右横线
\cline{2-3} 表示画出一条在第2栏位到第3栏位的横线段,其他栏位将不会有横线段
用tabular创建的表格如何加一个标题
\begin{table}
\begin{center}
\begin{spacing}{1.5} %调整表格的行距
\caption{Surface water regression coefficient}
\label{table2}
%EXCEL表格直接复制过来的 注意数学符号需要加上$...$
\begin{tabular}{|c|c|c|}
\hline
{\bf Parameter} & {\bf Parameter estimation} & {\bf Parameter confidence interval} \\
\hline
$\beta _0$ & -83.0232 & [-642.9658,476.9194] \\
\hline
$\beta _1$ & 0.0008 & [-0.0265,0.0281] \\
\hline
$\beta _2$ & 0.3998 & [-7.0124,7.8119] \\
\hline
\multicolumn{ 3}{|c|}{R2=0.3620} \\
\hline
\end{tabular}
\end{spacing}
\end{center}
\end{table}
表格中的内容自动换行
\documentclass{article}
\usepackage{makecell}
\begin{document}
\section{One}
\begin{center}
\begin{tabular}{|c|>{\makecell*[c]}c|}
\hline
\makecell[tl]{Left aligned \\ cell text} & 1--2 \\
\hline
\makecell*[r]{Right Aligned \\ cell text} & 3--4 \\
\hline
\makecell[{}{p{3cm}}]{This is a \\ vertical alignment} & 5--6 \\
\hline
%自动换行
\makecell[c{>{\parindent 2em}p{3cm}}]{V \&{} H alignments} & 7--8 \\
\hline
\end{tabular}
\end{center}
\end{document}
在线制作表格网站:http://www.tablesgenerator.com/
EXCEL表格转化为LaTex格式需要的小工具(Excel2LaTeX.xla)