我正在尝试在乳胶中绘制一个表格。以下是代码
\begin{table}[H]
\centering
\caption{Objective Measures for the Quality of Reconstructed Videos using NITRA, OMP and STOMP}
\noindent\resizebox{\textwidth}{!}{\begin{tabular}{@{}cccc|cccc}
\hline
\multicolumn{4}{c|}{Averaged total runtime (s) of different algorithms for images } & \multicolumn{4}{c}{Averaged total runtime (s) of different algorithms for videos} \\
NITRA & CoSaMP & OMP & StOMP & NITRA & CoSaMP & OMP & StOMP\\
\hline
1.3067 & 2.5134 & 11.8195 & 19.5301 & 10.4523 & 14.7223 & 73.2695 & 124.7040 \\
\hline
\label{run}
\end{tabular}}
\end{table}
子标题“NITRA 等”未正确对齐。此外,标题“平均总数......”应采用两行格式,以便于阅读。我该怎么做?
答案1
\resizebox
如果可以的话,请尽量避免,在这种情况下,您就这样做吧。
使用一行来存储公共信息,使用另一行来存储附加位;这样就\cmidrule
可以看出受影响的列是什么。
使用可以获得更好的外观;根据您的特定值siunitx
设置数字。table-format
\addtolength
我首先使用默认值排版表格\tabcolsep
,然后将超出的部分除以 14(列间距数),从而计算出长度。如果收缩过多(我认为超过 4pt),\small
请先插入\begin{tabular}
并重试。在特别困难的情况下,\footnotesize
应该可以解决问题。较小的字体大小会使表格难以阅读,您应该重新考虑如何呈现它。
\documentclass{article}
\usepackage{booktabs,siunitx}
\begin{document}
\begin{table}[htp]
\centering
\caption{Objective Measures for the Quality of Reconstructed
Videos using NITRA, OMP and STOMP}\label{run}
\addtolength\tabcolsep{-1.5pt}
\begin{tabular}{
@{}
S[table-format=1.4]
S[table-format=1.4]
S[table-format=2.4]
S[table-format=2.4]
S[table-format=2.4]
S[table-format=2.4]
S[table-format=2.4]
S[table-format=3.4]
@{}
}
\toprule
\multicolumn{8}{c}{Averaged total runtime (in \si{\second}) of different algorithms} \\
\midrule
\multicolumn{4}{c}{for images} & \multicolumn{4}{c}{for videos}\\
\cmidrule(r){1-4}\cmidrule(l){5-8}
{NITRA} & {CoSaMP} & {OMP} & {StOMP} & {NITRA} & {CoSaMP} & {OMP} & {StOMP} \\
\midrule
1.3067 & 2.5134 & 11.8195 & 19.5301 & 10.4523 & 14.7223 & 73.2695 & 124.7040 \\
1.3067 & 2.5134 & 11.8195 & 19.5301 & 10.4523 & 14.7223 & 73.2695 & 124.7040 \\
1.3067 & 2.5134 & 11.8195 & 19.5301 & 10.4523 & 14.7223 & 73.2695 & 124.7040 \\
\bottomrule
\end{tabular}
\end{table}
\end{document}
例如,如果数据只有一行,则最好以不同的方式组织表格。
\documentclass{article}
\usepackage{booktabs,siunitx}
\begin{document}
\begin{table}[htp]
\centering
\caption{Objective Measures for the Quality of Reconstructed
Videos using NITRA, OMP and STOMP}\label{run}
\addtolength\tabcolsep{-1.5pt}
\begin{tabular}{
@{}
l
S[table-format=2.4]
S[table-format=3.4]
@{}
}
\toprule
\multicolumn{3}{l}{Averaged total runtime (in \si{\second})} \\
\multicolumn{3}{l}{of different algorithms} \\
\midrule
& {images} & {videos} \\
\midrule
NITRA & 1.3067 & 10.4523 \\
CoSaMP & 2.5134 & 14.7223 \\
OMP & 11.8195 & 73.2695 \\
StOMP & 19.5301 & 124.7040 \\
\bottomrule
\end{tabular}
\end{table}
\end{document}
答案2
检查一下:
\documentclass{article}
\begin{document}
\begin{table}[H]
\centering
\caption{Objective Measures for the Quality of Reconstructed Videos using NITRA, OMP and STOMP}
\noindent\begin{tabular}{@{}cccc|cccc@{}}
\hline
\multicolumn{4}{c|}{\parbox{.4\textwidth}{Averaged total runtime (s) of different algorithms for images }} & \multicolumn{4}{c}{\parbox{.4\textwidth}{Averaged total runtime (s) of different algorithms for videos}} \\
NITRA & CoSaMP & OMP & StOMP & NITRA & CoSaMP & OMP & StOMP\\
\hline
1.3067 & 2.5134 & 11.8195 & 19.5301 & 10.4523 & 14.7223 & 73.2695 & 124.7040 \\
\hline
\label{run}
\end{tabular}
\end{table}
\end{document}
输出:
答案3
另一种方法是使用booktabs
\documentclass{article}
\usepackage{float,booktabs}
\begin{document}
\begin{table}[H]
\centering
\begin{tabular}{cccc|cccc}
\toprule
\multicolumn{4}{c|}{\parbox{.4\textwidth}{Averaged total runtime (s) of different algorithms for images }}
& \multicolumn{4}{c}{\parbox{.4\textwidth}{Averaged total runtime (s) of different algorithms for videos}} \\
\midrule
NITRA & CoSaMP & OMP & StOMP & NITRA & CoSaMP & OMP & StOMP\\
\midrule
1.3067 & 2.5134 & 11.8195 & 19.5301 & 10.4523 & 14.7223 & 73.2695 & 124.7040 \\
\bottomrule
\end{tabular}
\caption{Objective Measures for the Quality of Reconstructed Videos using NITRA, OMP and STOMP}
\end{table}
\end{document}
答案4
我会缩小两个标题的共同部分。此外,不要使用[H]
with table
,因为 atable
是浮动的。如果您希望表格保持在原位,请使用capt-of
或caption
包来获取标题。如果表格几乎适合页面,您可以通过使用 减少列间距来获得一些空间\setlength\tabcolsep{...}
。
\documentclass{article}
\usepackage{booktabs}
\usepackage{capt-of}
\begin{document}
\begin{center}
\captionof{table}{Objective Measures for the Quality of Reconstructed
Videos using NITRA, OMP and STOMP}\label{run}
\setlength\tabcolsep{0.4em}
\begin{tabular}{@{}cccc|cccc@{}}
\toprule
\multicolumn{8}{c}{Averaged total runtime (in s) of different algorithms} \\
\multicolumn{4}{c|}{for images}
& \multicolumn{4}{c}{for videos}\\
NITRA & CoSaMP & OMP & StOMP
& NITRA & CoSaMP & OMP & StOMP\\
\midrule
1.3067 & 2.5134 & 11.8195 & 19.5301
& 10.4523 & 14.7223 & 73.2695 & 124.7040 \\
\bottomrule
\end{tabular}
\end{center}
\end{document}