表格外边框缺失

表格外边框缺失

我有一张表格,最后一列右侧没有边框。代码如下:

\documentclass[runningheads,a4paper]{llncs}

    \usepackage{amssymb}
    \setcounter{tocdepth}{2}
    \usepackage{graphicx}
    \usepackage[latin1]{inputenc}
    \usepackage[english]{babel}

    \usepackage{float}
    \usepackage{booktabs}


    \usepackage{mathtools}

    \usepackage{amsmath}
    \usepackage[english]{babel}
    \usepackage{booktabs,array}
    \usepackage{lipsum}
    \usepackage{hhline}% http://ctan.org/pkg/hhline

    \DeclareMathOperator\prb{probability}
    \DeclareMathOperator\cost{cost}
    \DeclareMathOperator\child{child}

    \setcounter{secnumdepth}{5}
    \begin{document}


\begin{table}[!htbp]
  \centering
  \caption{Countermeasure solutions for connected vehicle}
   \label{Countermeasure solutions for connected vehicle}
   \begin{tabular}{ |m{2cm}| m{2.5cm} | m{2cm}|m{2cm}| m{2cm} | }
    \hline
    ID  &  cost  &  severity & probability & risk  \\ 
    \hline
        C1      &  300   &  8    & 0.5 \\
     \hline
        C2      &  200   &  8    & 0.5
    \\ \hline
        C1 and C2        &  500= 300 + 200   &  8   & 0.5
    \\ \hline
        T1     &  300    &  8    & 0.5
    \\ \hline
        T2     &  300    &  8    & 0.5
    \\ \hline

  \end{tabular}
\end{table}


\end{document}

在此处输入图片描述

所以,为什么我的列上没有任何边框?

答案1

右侧的行由最左侧的单元格设置,在大多数行中都省略了该单元格。已修复:

\begin{table}[!htbp]
  \centering
  \caption{Countermeasure solutions for connected vehicle}
   \label{Countermeasure solutions for connected vehicle}
   \begin{tabular}{ |m{2cm}| m{2.5cm} | m{2cm}|m{2cm}| m{2cm} | }
    \hline
    ID  &  cost  &  severity & probability & risk  \\
    \hline
        C1      &  300   &  8    & 0.5 & \\
     \hline
        C2      &  200   &  8    & 0.5 &
    \\ \hline
        C1 and C2        &  500= 300 + 200   &  8   & 0.5 &
    \\ \hline
        T1     &  300    &  8    & 0.5 &
    \\ \hline
        T2     &  300    &  8    & 0.5 &
    \\ \hline

  \end{tabular}
\end{table}

结果

顺便说一句,您已加载了两次包booktabs。您为什么不使用它呢?

\documentclass[runningheads,a4paper]{llncs}

\usepackage{booktabs}

\begin{document}
\begin{table}
  \centering
  \caption{Countermeasure solutions for connected vehicle}
   \label{Countermeasure solutions for connected vehicle}
   \begin{tabular}{lllll}
    \toprule
    ID  &  Cost  &  Severity & Probability & Risk  \\
    \midrule
        C1      &  300   &  8    & 0.5 & \\
        C2      &  200   &  8    & 0.5 & \\
        C1 and C2        &  $500 = 300 + 200$ &  8   & 0.5 & \\
        T1     &  300    &  8    & 0.5 & \\
        T2     &  300    &  8    & 0.5 & \\
    \bottomrule
  \end{tabular}
\end{table}
\end{document}

带有 booktabs 的结果

答案2

创建表格时,必须使用多个“&”,因为“{ |m{2cm}| m{2.5cm} | m{2cm}|m{2cm}| m{2cm}| m{2cm} | }”中定义的列减一......

这里您定义了一个有 5 列的表,而您的代码中只有 3 个列分隔符 (&)...因此,最后一列丢失了,并且 Latex 决定忽略所有最后一列,包括最后的“|”...

通过在表格每一行的换行符“\”前添加最后一个“&”,错误就被修复了,正如您在@Heiko Oberdiek 的回答中所看到的那样...

另外,您还必须小心多列:

参见下面的代码:

\documentclass[10pt,a4paper]{article}

\usepackage{amssymb}
\setcounter{tocdepth}{2}
\usepackage{graphicx}
\usepackage[latin1]{inputenc}
\usepackage[english]{babel}
\usepackage{float}
\usepackage{booktabs}
\usepackage{mathtools}
\usepackage{amsmath}
\usepackage[english]{babel}
\usepackage{booktabs,array} 
\usepackage{lipsum}
\usepackage{hhline}% http://ctan.org/pkg/hhline

\DeclareMathOperator\prb{probability}
\DeclareMathOperator\cost{cost}
\DeclareMathOperator\child{child}

\setcounter{secnumdepth}{5}

\begin{document}


\begin{table}[!htbp]
  \centering
  \caption{Countermeasure solutions for connected vehicle}
  \label{tab:CountSolfCV}
  \begin{tabular}{ |m{2cm}| m{2.5cm} | m{2cm}|m{2cm}| m{2cm} | }
    \hline
    ID  &  cost  &  severity & probability & risk  \\ 
    \hline
    C1      &  300   &  8    & \multicolumn{2}{p{4cm}}{0.5} \\
    \hline
    C2      &  200   &  8    & \multicolumn{2}{p{4cm}|}{0.5}
    \\ \hline
    C1 and C2        &  500= 300 + 200   &  8   & \multicolumn{2}{|p{4cm}}{0.5}
    \\ \hline
    T1     &  300    &  8    & \multicolumn{2}{|p{4cm}|}{ 0.5}
    \\ \hline
    T2     &  300    &  8    & 0.5 &
    \\ \hline  
  \end{tabular}
\end{table}

\end{document}

参见下图

在此处输入图片描述

多列的正确方法是值标签后的第二行,因为前一列有它自己的“|”,并且如果再添加一个,它将像接下来的两行一样进行双重打印,如果你不知道到底发生了什么,这似乎是正确的。

PS:表格、图形等的标签是为了方便我们查阅表格或图形……最好使用小而“有特色”的标签。

相关内容