问题
latex 中想制作论文常见的表格,整理自己常用模板,与常用命令。
命令
调整行高
\renewcommand{\arraystretch}{1.3}
调整列宽
\begin{tabular}{ m{3.1cm}<{\centering} m{0.8cm}<{\centering} m{0.8cm}<{\centering} m{0.8cm}<{\centering} m{0.8cm}<{\centering}}
高度方向
- 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)
写入的文字的顶端,中间,底端对齐到表格中央,是中央,
水平方向
- l---------left-justified column
- c--------centred column
- r---------right-justified column
另一种方法
- left, \raggedright
- right, \raggedleft
- center, \centering
绘制横线
\hline
在 \usepackage{booktabs}
包中有,
- \toprule
- \midrule
- \bottomrule
\toprule[1pt]
\midrule[3pt]
\bottomrule[5pt]
去掉两端多余横线
使用 @{}
表格宽度设置的两端
\begin{tabular}{@{}lll@{}}
长度单位
Abbreviation | Value |
---|---|
pt | a point is approximately 1/72.27 inch, that means about 0.0138 inch or 0.3515 mm (exactly point is defined as 1/864 of American printer’s foot that is 249/250 of English foot) |
mm | a millimeter |
cm | a centimeter |
in | inch |
ex | roughly the height of an ‘x’ (lowercase) in the current font (it depends on the font used) |
em | roughly the width of an ‘M’ (uppercase) in the current font (it depends on the font used) |
mu | math unit equal to 1/18 em, where em is taken from the math symbols family |
sp | so-called “special points”, a low-level unit of measure where 65536sp=1pt |
改变线宽
竖直线,\vrule width 1pt
, 水平线, \noalign{\hrule height 1.2pt}
\begin{tabular}{
|c!{\vrule width 1pt}
c!{\vrule width 1.6pt}
c!{\vrule width 2.2pt}
c!{\vrule width 2.8pt}
c!{\vrule width 3.4pt}
c!{\vrule width 4pt}
c!{\vrule width 4.6pt}
}
\hline
& & & & & & \\
\noalign{\hrule height 1.2pt}
& & & & & & \\
\noalign{\hrule height 1.6pt}
& & & & & & \\
\noalign{\hrule height 2pt}
& & & & & & \\
\noalign{\hrule height 2.6pt}
& & & & & & \\
\noalign{\hrule height 3.4pt}
& & & & & & \\
\noalign{\hrule height 4pt}
& & & & & & \\
\noalign{\hrule height 4.6pt}
\end{tabular}
脚注 footnote
\usepackage{threeparttable} % Footnot under the table
\usepackage{tablefootnote} % Footnot under the table
\begin{table}[htpb]
\begin{center}
\begin{threeparttable}
\renewcommand{\arraystretch}{1.3}
\caption{Table}
\begin{tabular}{ @{}m{3.1cm}<{\centering} m{0.8cm}<{\centering} m{0.8cm}<{\centering} m{0.8cm}<{\centering} m{0.8cm}<{\centering}@{}}
\toprule
Square & Ellip. & Circ. & Surf. & Rect. \\
\midrule
A & Failed & 19 & 98 & 62 \\
B & 14.4 & 72 & 68 & 4.7 \\
C & - & 17\% & 17\% & 8\% \\
\bottomrule
\end{tabular}
\label{Table::M}
\begin{tablenotes}\footnotesize{\color{red}
\item[1] Hello.
\item[2] value of some parameters
}
\end{tablenotes}
\end{threeparttable}
\end{center}
\end{table}
参考 https://blog.csdn.net/jh1513/article/details/125143848
模板
模板一
\begin{table}[htpb]
\begin{center}
\renewcommand{\arraystretch}{1.3}
\caption{Table}
\begin{tabular}{ @{}m{3.1cm}<{\centering} m{0.8cm}<{\centering} m{0.8cm}<{\centering} m{0.8cm}<{\centering} m{0.8cm}<{\centering}@{}}
\toprule
Square & Ellip. & Circ. & Surf. & Rect. \\
\midrule
A & Failed & 19 & 98 & 62 \\
B & 14.4 & 72 & 68 & 4.7 \\
C & - & 17\% & 17\% & 8\% \\
\bottomrule
\end{tabular}
\label{Table::M}
\end{center}
\end{table}
模板二
\begin{table}[htpb]
\begin{center}
\renewcommand{\arraystretch}{1.3}
\caption{Table}
% \begin{tabular}{ c{3.1cm} | c{0.8cm} | c{0.8cm} | c{0.8cm} | c{0.8cm}}
\begin{tabular}{ m{3.1cm} | m{0.8cm}| m{0.8cm} | m{0.8cm} | m{0.8cm}}
\hline
Square & Ellip. & Circ. & Surf. & Rect. \\
\hline
A & Failed & 19 & 98 & 62 \\
B & 14.4 & 72 & 68 & 4.7 \\
C & - & 17\% & 17\% & 8\% \\
\hline
\end{tabular}
\label{Table::M}
\end{center}
\end{table}
模板三
\begin{table}[htpb]
\begin{center}
\renewcommand{\arraystretch}{1.3}
\caption{Table}
\begin{tabular}{ m{3.1cm} | m{0.8cm}| m{0.8cm} | m{0.8cm} | m{0.8cm}}
\hline \hline
Square & Ellip. & Circ. & Surf. & Rect. \\
\hline
A & Failed & 19 & 98 & 62 \\
B & 14.4 & 72 & 68 & 4.7 \\
C & - & 17\% & 17\% & 8\% \\
\hline \hline
\end{tabular}
\label{Table::M}
\end{center}
\end{table}
如果把 \hline 改成 \toprule 等会导致 数线不连续
参考
https://nasa.github.io/nasa-latex-docs/html/examples/table.html
https://www.overleaf.com/learn/latex/Tables