表格有误。垂直线超出表格的一行

表格有误。垂直线超出表格的一行

这是我遇到问题的表格片段:

\captionof{table}{Risultati sperimentali per il dominio Rovers}
\begin{tabular}{|c|cc|cc|cc|cc|cc|}
\cline{1-11}
\multicolumn{1}{|c|}{Istanza}&\multicolumn{2}{|c|}{Vincoli}&\multicolumn{2}{|c|}{LAMA}&\multicolumn{2}{|c|}{MERCURY}&\multicolumn{2}{|c|}{lprpgp}&\multicolumn{2}{|c|}{HPLAN-P}\\ 
&\#sg&\#ag&sg&ag&sg&ag&sg&ag&sg&ag\\ \cline{1-11}
% 1&-&-&?&?&?&?&?&?&?&?\\
% 2&-&-&?&?&?&?&?&?&?&?\\
3&0&4&-&50.0&-&50.0&-&100.0&?&100.0\\
4&0&4&-&50.0&-&50.0&-&100.0&?&?\\
5&0&4&-&50.0&-&50.0&-&50.0&?&100.0\\
6&0&4&-&0.0&-&0.0&-&50.0&?&60.0\\
7&0&5&-&60.0&-&60.0&-&80.0&?&100.0\\
8&0&6&-&67.0&-&100.0&-&100.0&?&100.0\\
9&0&6&-&83.0&-&83.0&-&67.0&?&100.0\\
10&0&6&-&67.0&-&67.0&-&100.0&?&100.0\\
11&0&6&-&50.0&-&33.0&-&83.0&?&?\\
12&0&6&-&100.0&-&67.0&-&67.0&?&100.0\\
13&0&6&-&100.0&-&67.0&-&100.0&?&100.0\\
14&0&6&-&83.0&-&83.0&-&83.0&?&?\\
15&0&6&-&83.0&-&83.0&-&100.0&?&?\\
16&0&6&-&67.0&-&67.0&-&83.0&?&?\\
17&0&8&-&88.0&-&88.0&-&100.0&?&?\\
18&0&8&-&88.0&-&100.0&-&88.0&?&?\\
19&0&8&-&63.0&-&63.0&-&100.0&?&?\\
20&0&10&-&80.0&-&80.0&?&?&?&?\\
\cline{1-11}
\label{table:trucks_data}
\end{tabular}

如你所见,第一列的垂直线是错误的。

答案1

更改\cline{1-1}\hline您想要的整个表格宽度(避免必须计算)并将 \label 移到表格环境之外。 \documentclass[border=5mm]{standalone}

\begin{document}
\begin{tabular}{|c|cc|cc|cc|cc|cc|}\hline
%\cline{1-11}
\multicolumn{1}{|c|}{Istanza}&\multicolumn{2}{|c|}{Vincoli}&\multicolumn{2}{|c|}{LAMA}&\multicolumn{2}{|c|}{MERCURY}&\multicolumn{2}{|c|}{lprpgp}&\multicolumn{2}{|c|}{HPLAN-P}\\ 
&\#sg&\#ag&sg&ag&sg&ag&sg&ag&sg&ag\\\hline% \cline{1-11}
% 1&-&-&?&?&?&?&?&?&?&?\\
% 2&-&-&?&?&?&?&?&?&?&?\\
3&0&4&-&50.0&-&50.0&-&100.0&?&100.0\\
4&0&4&-&50.0&-&50.0&-&100.0&?&?\\
5&0&4&-&50.0&-&50.0&-&50.0&?&100.0\\
6&0&4&-&0.0&-&0.0&-&50.0&?&60.0\\
7&0&5&-&60.0&-&60.0&-&80.0&?&100.0\\
8&0&6&-&67.0&-&100.0&-&100.0&?&100.0\\
9&0&6&-&83.0&-&83.0&-&67.0&?&100.0\\
10&0&6&-&67.0&-&67.0&-&100.0&?&100.0\\
11&0&6&-&50.0&-&33.0&-&83.0&?&?\\
12&0&6&-&100.0&-&67.0&-&67.0&?&100.0\\
13&0&6&-&100.0&-&67.0&-&100.0&?&100.0\\
14&0&6&-&83.0&-&83.0&-&83.0&?&?\\
15&0&6&-&83.0&-&83.0&-&100.0&?&?\\
16&0&6&-&67.0&-&67.0&-&83.0&?&?\\
17&0&8&-&88.0&-&88.0&-&100.0&?&?\\
18&0&8&-&88.0&-&100.0&-&88.0&?&?\\
19&0&8&-&63.0&-&63.0&-&100.0&?&?\\
20&0&10&-&80.0&-&80.0&?&?&?&?\\\hline
%\cline{1-11}
\end{tabular}
\label{table:trucks_data}
\end{document}

在此处输入图片描述

答案2

  • \label{}不是空的,因此它确实会开始新的表格单元格和行。更好的位置是紧挨着标题之后(或标题内)。

  • 通常,空单元格使用破折号,而不是连字符。

  • siunitx允许在小数点处对齐数字。

  • 如果只移动水平线,表格会看起来更专业。包booktabs在这里提供帮助。

完整示例:

\documentclass{article}
\usepackage{array}
\usepackage{booktabs}
\usepackage{caption}
\usepackage{siunitx}

\begin{document}
\begingroup
  % LaTeX's default setting assume captions below the figure.
  % Package `caption` fixes the spacing for `table`'s, but
  % is a similated table, thus the spacing is fixed manually 
  % by exchanging `\belowcaptionskip` with `\abovecaptionskip`.
  \setlength{\dimen0 }{\belowcaptionskip}%
  \setlength{\belowcaptionskip}{\abovecaptionskip}%
  \setlength{\abovecaptionskip}{\dimen0 }%
  \captionof{table}{Risultati sperimentali per il dominio Rovers}
  \label{table:trucks_data}
  \begin{tabular}{
    S[table-format=2.0]
    c S[table-format=2.0]
    c S[table-format=3.1]
    c S[table-format=3.1]
    c S[table-format=3.1]
    c S[table-format=3.1]
  }
    \toprule
    \multicolumn{1}{c}{Istanza} &
    \multicolumn{2}{c}{Vincoli} &
    \multicolumn{2}{c}{LAMA} &
    \multicolumn{2}{c}{MERCURY} &
    \multicolumn{2}{c}{lprpgp} &
    \multicolumn{2}{c}{HPLAN-P}
    \\
    \cmidrule(lr){2-3}
    \cmidrule(lr){4-5}
    \cmidrule(lr){6-7}
    \cmidrule(lr){8-9}
    \cmidrule(lr){10-11}
    & {\#sg} & {\#ag} & {sg} & {ag} & {sg} & {ag} & {sg} & {ag} & {sg} & {ag}
    \\
    \midrule
     % 1 & --- & --- & ? & ? & ? & ? & ? & ? & ? & ? \\
     % 2 & --- & --- & ? & ? & ? & ? & ? & ? & ? & ? \\
     3 & 0 &  4 & --- &  50.0 & --- &  50.0 & --- & 100.0 & ? & 100.0 \\
     4 & 0 &  4 & --- &  50.0 & --- &  50.0 & --- & 100.0 & ? &   ?   \\
     5 & 0 &  4 & --- &  50.0 & --- &  50.0 & --- &  50.0 & ? & 100.0 \\
     6 & 0 &  4 & --- &   0.0 & --- &   0.0 & --- &  50.0 & ? &  60.0 \\
     7 & 0 &  5 & --- &  60.0 & --- &  60.0 & --- &  80.0 & ? & 100.0 \\
     8 & 0 &  6 & --- &  67.0 & --- & 100.0 & --- & 100.0 & ? & 100.0 \\
     9 & 0 &  6 & --- &  83.0 & --- &  83.0 & --- &  67.0 & ? & 100.0 \\
    10 & 0 &  6 & --- &  67.0 & --- &  67.0 & --- & 100.0 & ? & 100.0 \\
    11 & 0 &  6 & --- &  50.0 & --- &  33.0 & --- &  83.0 & ? &   ?   \\
    12 & 0 &  6 & --- & 100.0 & --- &  67.0 & --- &  67.0 & ? & 100.0 \\
    13 & 0 &  6 & --- & 100.0 & --- &  67.0 & --- & 100.0 & ? & 100.0 \\
    14 & 0 &  6 & --- &  83.0 & --- &  83.0 & --- &  83.0 & ? &   ?   \\
    15 & 0 &  6 & --- &  83.0 & --- &  83.0 & --- & 100.0 & ? &   ?   \\
    16 & 0 &  6 & --- &  67.0 & --- &  67.0 & --- &  83.0 & ? &   ?   \\
    17 & 0 &  8 & --- &  88.0 & --- &  88.0 & --- & 100.0 & ? &   ?   \\
    18 & 0 &  8 & --- &  88.0 & --- & 100.0 & --- &  88.0 & ? &   ?   \\
    19 & 0 &  8 & --- &  63.0 & --- &  63.0 & --- & 100.0 & ? &   ?   \\
    20 & 0 & 10 & --- &  80.0 & --- &  80.0 &  ?  &   ?   & ? &   ?   \\
    \bottomrule
  \end{tabular}
\endgroup
\end{document}

结果

答案3

错误来自末尾的标签:它应该带有\caption(of)

我会让您的表格不带垂直线,而是使用booktabsSIunitx来正确对齐数字。我还用en dashes 替换了简单的破折号,并使用 a\multirow作为第一个列标题:

    \documentclass{article}

    \usepackage[utf8]{inputenc}
    \usepackage{array, caption,siunitx, booktabs,multirow}

    \pagestyle{empty}
    \raggedbottom

    \begin{document}

    \captionof{table}{Risultati sperimentali per il dominio Rovers}
    \label{table:trucks_data}\sisetup{table-number-alignment=center}
    \begin{tabular}{ccS[table-format=2]*{4}{cS[table-format=3.1]}}
    \addlinespace
    \toprule
    \multirow{2}{*}{Istanza} & \multicolumn{2}{c}{Vincoli} & \multicolumn{2}{c}{LAMA} & \multicolumn{2}{c}{MERCURY} & \multicolumn{2}{c}{lprpgp} & \multicolumn{2}{c}{HPLAN-P}\\
    & \#sg &  {\#ag} & sg & {ag} & sg & {ag} & sg & {ag} & sg & {}ag\\
    \cmidrule(lr){1-11}
    1 & -- & {--} & ? & {?} & ? & {?} & ? & {?} & ? & {?}\\
    2 & -- & {--} & ? & {?} & ? & {?} & ? & {?} & ? & {?}\\
    3 & 0 & 4 & -- & 50.0 & -- & 50.0 & -- & 100.0 & ? & 100.0\\
    4 & 0 & 4 & -- & 50.0 & -- & 50.0 & -- & 100.0 & ? & {?}\\
    5 & 0 & 4 & -- & 50.0 & -- & 50.0 & -- & 50.0 & ? & 100.0\\
    6 & 0 & 4 & -- & 0.0 & -- & 0.0 & -- & 50.0 & ? & 60.0\\
    7 & 0 & 5 & -- & 60.0 & -- & 60.0 & -- & 80.0 & ? & 100.0\\
    8 & 0 & 6 & -- & 67.0 & -- & 100.0 & -- & 100.0 & ? & 100.0\\
    9 & 0 & 6 & -- & 83.0 & -- & 83.0 & -- & 67.0 & ? & 100.0\\
    10 & 0 & 6 & -- & 67.0 & -- & 67.0 & -- & 100.0 & ? & 100.0\\
    11 & 0 & 6 & -- & 50.0 & -- & 33.0 & -- & 83.0 & ? & {?}\\
    12 & 0 & 6 & -- & 100.0 & -- & 67.0 & -- & 67.0 & ? & 100.0\\
    13 & 0 & 6 & -- & 100.0 & -- & 67.0 & -- & 100.0 & ? & 100.0\\
    14 & 0 & 6 & -- & 83.0 & -- & 83.0 & -- & 83.0 & ? & {?}\\
    15 & 0 & 6 & -- & 83.0 & -- & 83.0 & -- & 100.0 & ? & {?}\\
    16 & 0 & 6 & -- & 67.0 & -- & 67.0 & -- & 83.0 & ? & {?}\\
    17 & 0 & 8 & -- & 88.0 & -- & 88.0 & -- & 100.0 & ? & {?}\\
    18 & 0 & 8 & -- & 88.0 & -- & 100.0 & -- & 88.0 & ? & {?}\\
    19 & 0 & 8 & -- & 63.0 & -- & 63.0 & -- & 100.0 & ? & {?}\\
    20& 0 & 10 & -- & 80.0 & -- & 80.0 & ? & {?} & ? & {?}\\
    \bottomrule
    \end{tabular}
    \end{document}

在此处输入图片描述

相关内容