我遇到了一个奇怪的问题。我的表格格式不正确。
\documentclass{article}
\begin{document}
\begin{table}
\centering
\caption{Dataset Description}
\setlength{\tabcolsep}{0.15cm}
\begin{tabular}{|l l c c c|}
\hline \\
Name & Type & Train Size & Test Size & Feature Size \\
\hline \\
Adult & Binary & 32561 & 16281 & 123\\[0.05cm]
Galaxy & 90.44 & 90.12 & 87.94 & 86.47 \\[0.05cm]
Mediamill & 97.86 & 97.89 & 97.86 & 97.76 \\[0.05cm]
Rcv & 97.86 & 97.89 & 97.86 & 97.76 \\[0.05cm]
Siam & 80.37 & 80.62 & 80.20 & 79.19 \\[0.05cm]
Scene & 80.37 & 80.62 & 80.20 & 79.19 \\[0.05cm]
Yeast & 80.37 & 80.62 & 80.20 & 79.19 \\[0.05cm]
\hline \\
\end{tabular}
\label{tab:data_desc}
\end{table}
\end{document}
答案1
有一些方法可以实现更大的垂直间距
下面的第二个表格包含\multirow
,空的额外行,减少行跳过的空的额外行和一种bigstrut
方法
- 可能还有其他方法...
- 提供的长度是我自己选择的,当然可以改变
\documentclass{article}
\usepackage{bigstrut}
\usepackage{multirow}
\newlength{\myextraspace}
\setlength{\myextraspace}{0.05cm}
\begin{document}
\begin{table}
\centering
\caption{Dataset Description}
\setlength{\tabcolsep}{0.15cm}
\begin{tabular}{|*{2}l*{3}c|}
\hline
Name & Type & Train Size & Test Size & Feature Size \\
\hline
Adult & Binary & 32561 & 16281 & 123\\[0.05cm]
Galaxy & 90.44 & 90.12 & 87.94 & 86.47 \\[0.05cm]
Mediamill & 97.86 & 97.89 & 97.86 & 97.76 \\[0.05cm]
Rcv & 97.86 & 97.89 & 97.86 & 97.76 \\[0.05cm]
Siam & 80.37 & 80.62 & 80.20 & 79.19 \\[0.05cm]
Scene & 80.37 & 80.62 & 80.20 & 79.19 \\[0.05cm]
Yeast & 80.37 & 80.62 & 80.20 & 79.19 \\[0.05cm]
\hline
\end{tabular}
Now the changed table
\begin{tabular}{|*{2}l*{3}c|}
\hline
\multirow{2}{*}{Name} & \multirow{2}{*}{Type} & \multirow{2}{*}{Train Size} & \multirow{2}{*}{Test Size} & \multirow{2}{*}{Feature Size} \tabularnewline
& & & & \tabularnewline
\hline
& & & & \tabularnewline
Name & Type & Train Size & Test Size & Feature Size \tabularnewline
& & & & \tabularnewline
\hline
& & & & \tabularnewline[-1ex]
Name & Type & Train Size & Test Size & Feature Size \tabularnewline
& & & & \tabularnewline[-1ex]
\hline
Name & Type & Train Size & Test Size & Feature Size \bigstrut\tabularnewline
\hline
Adult & Binary & 32561 & 16281 & 123.00\tabularnewline[\myextraspace]
Galaxy & 90.44 & 90.12 & 87.94 & 86.47 \tabularnewline[\myextraspace]
Mediamill & 97.86 & 97.89 & 97.86 & 97.76 \tabularnewline[\myextraspace]
Rcv & 97.86 & 97.89 & 97.86 & 97.76 \tabularnewline[\myextraspace]
Siam & 80.37 & 80.62 & 80.20 & 79.19 \tabularnewline[\myextraspace]
Scene & 80.37 & 80.62 & 80.20 & 79.19 \tabularnewline[\myextraspace]
Yeast & 80.37 & 80.62 & 80.20 & 79.19 \tabularnewline[\myextraspace]
\hline
\end{tabular}
\label{tab:data_desc}
\end{table}
\end{document}
答案2
以下是我的做法:
\documentclass{article}
\usepackage{siunitx}
\usepackage{booktabs}
\usepackage{caption}
\DeclareCaptionLabelSeparator{spacing}{:\quad}
\captionsetup{
labelsep = spacing,
tableposition = top,
font = small,
labelfont = sc
}
\begin{document}
\begin{table}
\centering
\caption{Dataset Description.}
\label{tab:data_desc}
\begin{tabular}{l *{3}{S[table-format = 2.2]} S[table-format = 3.2]}
\toprule
Name & {Type} & {Train Size} & {Test Size} & {Feature Size} \\
\midrule
Adult & {Binary} & {32561} & {16281} & 123.00 \\
Galaxy & 90.44 & 90.12 & 87.94 & 86.47 \\
Mediamill & 97.86 & 97.89 & 97.86 & 97.76 \\
Rcv & 97.86 & 97.89 & 97.86 & 97.76 \\
Siam & 80.37 & 80.62 & 80.20 & 79.19 \\
Scene & 80.37 & 80.62 & 80.20 & 79.19 \\
Yeast & 80.37 & 80.62 & 80.20 & 79.19 \\
\bottomrule
\end{tabular}
\end{table}
\end{document}
答案3
实现漂亮表格的简单方法是使用booktabs
包:
\documentclass{article}
\usepackage{booktabs}
\begin{document}
\begin{table}
\centering
\caption{Dataset Description}
\setlength{\tabcolsep}{0.15cm}
\renewcommand{\arraystretch}{1.1}%1.2
\begin{tabular}{l l c c c}
\toprule
Name & Type & Train Size & Test Size & Feature Size \\
\midrule
Adult & Binary & 32561 & 16281 & 123 \\
Galaxy & 90.44 & 90.12 & 87.94 & 86.47 \\
Mediamill & 97.86 & 97.89 & 97.86 & 97.76 \\
Rcv & 97.86 & 97.89 & 97.86 & 97.76 \\
Siam & 80.37 & 80.62 & 80.20 & 79.19 \\
Scene & 80.37 & 80.62 & 80.20 & 79.19 \\
Yeast & 80.37 & 80.62 & 80.20 & 79.19 \\
\bottomrule
\end{tabular}
\label{tab:data_desc}
\end{table}
\end{document}
如果您希望行间距更大,则将系数调整为\renewcommand{\arraystretch}{1.1}
所需值。当然,此表故意没有垂直线。