常见的使用Latex生成两种效果的表格,其实现区别在于生成横线的方式不同:
- 第一种是直接使用\hline生成横线
- 第二种是使用\toprule顶部线,\midrule中间线,\bottomrule底部线
第一种生成的表格比较紧凑,代码如下,效果如下图所示:
\begin{table}[hp] %%参数: h:放在此处 t:放在顶端 b:放在底端 p:在本页
\renewcommand\arraystretch{1.2}
%\setlength{\abovecaptionskip}{0.cm}
%\setlength{\belowcaptionskip}{-0.cm}
\centering % 显示位置为中间
\textbf{Table 2}~~Parameters description.\\ %%表的标题
\begin{tabular}{p{45pt}l|ll|l} %第一列设置宽度为45pt 全为左对齐 没有分割线
%\setlength{\tabcolsep}{20mm}
\hline % 表格的横线
%\toprule % 顶部线
Parameters & & Definitions & Value & Source \\%[3pt]只改一行 %%表格第一行标题 % 表格中的内容,用&分开,\\表示下一行
\hline % 表格的横线
%\midrule % 中部线
$\beta_{1}$ & & xxxxabcdxxx & 1 & Estimation \\ %%表格内容
%\midrule
\multirow{2}[2]{*}{$\alpha_{3}$} & & aaa1 & \multirow{2}[2]{*}{1} & \multirow{2}[2]{*}{Estimation} \\
& & bbb2 & & \\
$d_{1}$ & & xxxxabcdxxx & 1 & Estimation \\
\multirow{3}[2]{*}{$1/\theta(t)$}& $\theta_{0}$ & 1aaa & 1 & Estimation \\
& $\theta_{1}$ & 2bbb & 1 & Estimation \\
& $\theta_{2}$ & 3ccc & 1 & Estimation \\
%\bottomrule % 底部线
\hline % 表格的横线
\end{tabular}
\end{table}
效果如下:
想要生成双线,只需要在相应位置使用两次\hline即可,效果如下:
第二种生成的表格比较宽松,四周有空隙,代码如下,效果如下图图所示:
\begin{table}[hp] %%参数: h:放在此处 t:放在顶端 b:放在底端 p:在本页
\renewcommand\arraystretch{1.2}
%\setlength{\abovecaptionskip}{0.cm}
%\setlength{\belowcaptionskip}{-0.cm}
\centering % 显示位置为中间
\textbf{Table 2}~~Parameters description.\\ %%表的标题
\begin{tabular}{p{45pt}l|ll|l} %第一列设置宽度为45pt 全为左对齐 没有分割线
%\setlength{\tabcolsep}{20mm}
%\hline % 表格的横线
\toprule % 顶部线
Parameters & & Definitions & Value & Source \\%[3pt]只改一行 %%表格第一行标题 % 表格中的内容,用&分开,\\表示下一行
%\hline % 表格的横线
\midrule % 中部线
$\beta_{1}$ & & xxxxabcdxxx & 1 & Estimation \\ %%表格内容
%\midrule
\multirow{2}[2]{*}{$\alpha_{3}$} & & aaa1 & \multirow{2}[2]{*}{1} & \multirow{2}[2]{*}{Estimation} \\
& & bbb2 & & \\
$d_{1}$ & & xxxxabcdxxx & 1 & Estimation \\
\multirow{3}[2]{*}{$1/\theta(t)$}& $\theta_{0}$ & 1aaa & 1 & Estimation \\
& $\theta_{1}$ & 2bbb & 1 & Estimation \\
& $\theta_{2}$ & 3ccc & 1 & Estimation \\
\bottomrule % 底部线
%\hline % 表格的横线
%\hline
\end{tabular}
\end{table}
效果如下:
如果中间需要多个横线,可以多次使用\midrule。