如何让 LaTeX 自动设置宽度大小,以便所有文本都在一行中?有没有最简单的代码可用?或者教我如何编辑单个列的宽度并让其余列相应改变。最简单的代码,无需使用任何附加函数,如 tabularx 或 tabularz
\begin{table*}[t]
\footnotesize
\begin{tabu} to \textwidth { | X[l] || X[c] | X[c] | X[c] || X[c] | X[c] | X[c] || X[c] | X[c] | X[c] | }
\hline
Method & Easy & Moderate & Hard & Easy & Moderate & Hard & Easy & Moderate & Hard \\
\hline
& \multicolumn{3}{c||}{Car} & \multicolumn{3}{c||}{Pedestrian} & \multicolumn{3}{c|}{Cyclist} \\
\hline
MCGD \cite{mcg-d} & 67.84 & 50.61 & 42.20 & 61.77 & 53.19 & 46.40 & 67.84 & 50.61 & 42.20 \\
\hline
MCG \cite{mcg} & 59.54 & 45.86 & 38.61 & 50.20 & 44.53 & 40.45 & 59.54 & 45.86 & 38.61 \\
\hline
SS \cite{selectivesearch} & 32.36 & 20.45 & 18.72 & 24.38 & 22.06 & 20.53 & 32.36 & 20.45 & 18.72 \\
\hline
EB \cite{edgeboxes} & 52.48 & 36.57 & 31.15 & 29.57 & 22.06 & 22.58 & 52.48 & 36.57 & 31.15 \\
\hline
3DOP \cite{3dop} & 95.39 & 82.85 & \textbf{82.25} & 89.48 & 83.29 & \textbf{74.94} & 95.11 & 77.63 & \textbf{77.38} \\
\hline
BING \cite{bing} & 8.50 & 5.37 & 10.93 & 24.64 & 27.21 & 32.23 & 8.50 & 5.37 & 10.93 \\
\hline
Ours & \textbf{95.64} & \textbf{83.15} & 77.54 & \textbf{96.46} & \textbf{87.77} & 74.94 & \textbf{95.63} & \textbf{91.44} & 73.96 \\
\hline
\end{tabu}
\caption{Recall of different proposal methods with an average of 500 proposals. The IOU criteria for car, pedestrian and cyclist are at 0.7, 0.5 and 0.5 respectively. In bold are the best results.}
\label{tab:results}
\end{table*}
答案1
如果我理解你的目的正确的话,你需要做的就是X[l]
替换
\begin{tabu} to \textwidth { | X[l] || X[c] | X[c] | X[c] || X[c] | X[c] | X[c] || X[c] | X[c] | X[c] | }
设置为l
。结果,第一列会稍微宽一些(这样单元格的内容才能全部放在一行),而其他 9 列会(非常)稍微窄一些。
使用更紧凑的符号,你应该这样写
\begin{tabu} to \textwidth { | l || *{3}{X[c]|} | *{3}{X[c]|} | *{3}{X[c]|} }
附录tabu
:考虑使用环境,而不是tabular*
环境。此外,不要简单地将九个数字列的内容居中,而要考虑将数字与各自的小数点对齐。我还想建议反转两个标题行的顺序,并通过删除所有垂直线和大多数水平线,并使用包的线条绘制命令来绘制剩余的几条水平线,使表格看起来更加“开放” booktabs
。
此外,由于您使用粗体突出显示单元格内容,请考虑对数字使用非扩展粗体字体;这样,粗体和常规粗体数字将在列中正确排列。在下面的代码中,这是通过提供指令来实现的\renewcommand{\bfdefault}{b}
里面环境table
。
总的来说,这些改变将使表格变得更加清晰和更具视觉吸引力。
(顺便说一下,第一列中的问号出现是因为示例代码无法解析指令\cite
。)
\documentclass{article}
\usepackage[letterpaper,margin=1in]{geometry} % set text block parameters appropriately
\usepackage{booktabs,siunitx,etoolbox,caption}
\begin{document}
\begin{table}
%% Command to use non-extended bold in the table:
\renewcommand{\bfdefault}{b} % use non-extended bold weight
\robustify{\textbf} % to make it work in "S" columns
\small % no need to go to \footnotesize, right?
\captionsetup{font=small,skip=0.333\baselineskip}
\setlength\tabcolsep{0pt} % make LaTeX figure out optimal intercolumn whitespace
\begin{tabular*}{\textwidth}{l @{\extracolsep{\fill}} *{9}{S[table-format=2.2]} }
\toprule
Method & \multicolumn{3}{c}{Car} & \multicolumn{3}{c}{Pedestrian} & \multicolumn{3}{c}{Cyclist}\\
\cmidrule{2-4} \cmidrule{5-7} \cmidrule{8-10}
& {Easy} & {Moderate} & {Hard} & {Easy} & {Moderate} & {Hard} & {Easy} & {Moderate} & {Hard} \\
\midrule
MCG-D \cite{mcg-d} & 67.84 & 50.61 & 42.20 & 61.77 & 53.19 & 46.40 & 67.84 & 50.61 & 42.20 \\
MCG \cite{mcg} & 59.54 & 45.86 & 38.61 & 50.20 & 44.53 & 40.45 & 59.54 & 45.86 & 38.61 \\
SS \cite{selectivesearch} & 32.36 & 20.45 & 18.72 & 24.38 & 22.06 & 20.53 & 32.36 & 20.45 & 18.72 \\
EB \cite{edgeboxes} & 52.48 & 36.57 & 31.15 & 29.57 & 22.06 & 22.58 & 52.48 & 36.57 & 31.15 \\
3DOP \cite{3dop} & 95.39 & 82.85 & \textbf{82.25} & 89.48 & 83.29 & \textbf{74.94} & 95.11 & 77.63 & \textbf{77.38} \\
BING \cite{bing} & 8.50 & 5.37 & 10.93 & 24.64 & 27.21 & 32.23 & 8.50 & 5.37 & 10.93 \\
Ours & \textbf{95.64} & \textbf{83.15} & 77.54 & \textbf{96.46} & \textbf{87.77} & 74.94 & \textbf{95.63} & \textbf{91.44} & 73.96 \\
\bottomrule
\end{tabular*}
\caption{Recall rates of different proposal methods with an average of 500 proposals. The IOU criteria for car, pedestrian and cyclist are at 0.7, 0.5 and 0.5 respectively. In bold are the best results.}
\label{tab:results}
\end{table}
\end{document}