Search code examples
latex

Disconnected vertical lines with Latex table using booktabs package


I want the vertical lines in my table disconnected like in the example below.

enter image description here

My attempt is getting me vertical lines like in the second table shown below, how can I reproduce the lines like in the example?

enter image description here

This is my code to generate my table

\usepackage{graphicx}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{multirow}
\usepackage{array}
\usepackage{makecell}
\usepackage[table,xcdraw]{xcolor}
\usepackage{booktabs}
\usepackage{arydshln}


\begin{document}
\begin{table}[h]
\begin{center}
\setlength{\tabcolsep}{8pt}
\renewcommand{\arraystretch}{1.0}
\begin{tabular}{c|cccc}
\toprule
classes  & abs\_rel & a1    & a2    & a3    \\ \midrule
Road    & 0.138               & 0.851          & 0.917          & 0.946 \\ %\hline
Vehicle & 0.135               & 0.855          & 0.920          & 0.948 \\ %\hline
Lane    & 0.135               & 0.855          & 0.920          & 0.947 \\ %\hline
\bottomrule
\end{tabular}
\end{center}
\end{table}
\end{document}

Solution

  • You can replicate the incorrect usage of booktabs with vertical lines if you refrain form loading the arydshln package. This package would fix some of the incompatibilities of booktabs with vertical lines.

    However please consider carefully if you really want your table to look like you made an error in coding it. It will look as if you don't know your latex.

    \documentclass{article}
    \usepackage{graphicx}
    \usepackage{amsmath}
    \usepackage{amssymb}
    \usepackage{multirow}
    \usepackage{array}
    \usepackage{makecell}
    \usepackage[table,xcdraw]{xcolor}
    \usepackage{booktabs}
    %\usepackage{arydshln}
    
    
    \begin{document}
    \begin{table}[h]
    \begin{center}
    \setlength{\tabcolsep}{8pt}
    \renewcommand{\arraystretch}{1.0}
    \begin{tabular}{c|cccc}
    \toprule
    classes  & abs\_rel & a1    & a2    & a3    \\ \midrule
    Road    & 0.138               & 0.851          & 0.917          & 0.946 \\ %\hline
    Vehicle & 0.135               & 0.855          & 0.920          & 0.948 \\ %\hline
    Lane    & 0.135               & 0.855          & 0.920          & 0.947 \\ %\hline
    \bottomrule
    \end{tabular}
    \end{center}
    \end{table}
    \end{document}