3

I am using the tabular function to create my table but the line that comes out seems to be disconnected. How do I fix this without changing the function ? I still need to use tabular.

\begin{table}
\centering
 \subfloat{%
   \begin{tabular}{|c|c|} \toprule
    A & 0.002s \\ 
    B & 0.05s \\
    C & \\ \bottomrule
   \end{tabular}
 }
 \caption{}
\end{table}

enter image description here

2
  • 7
    Lines from the booktabs package are intended to be used without vertical lines.
    – leandriis
    Commented Jan 13, 2021 at 22:42
  • 7
    you should always provide a test document not a fragment. This is purely a question about booktabs (which you do not mention) booktabs by design makes vertical rules unusable. Commented Jan 13, 2021 at 22:46

3 Answers 3

7

As explained here: https://tex.stackexchange.com/a/88939/231952, it is not a good idea to use vertical rules in tables. In any case, to answer your question, these commands will suffice:

\setlength{\aboverulesep}{0pt}
\setlength{\belowrulesep}{0pt}

Table 1. With booktabs and without vertical rules (best choice):

\begin{tabular}{cc} \toprule
    A & 0.002s \\ 
    B & 0.05s \\
    C & \\ \bottomrule
\end{tabular}

Table 2. Without booktabs (i.e. with standard rules):

\begin{tabular}{|c|c|} \hline
    A & 0.002s \\ 
    B & 0.05s \\
    C & \\ \hline
\end{tabular}

Table 3. With vertical rules and booktabs:

\setlength{\aboverulesep}{0pt}
\setlength{\belowrulesep}{0pt}
\begin{tabular}{|c|c|} \toprule
A & 0.002s \\ 
B & 0.05s \\
C & \\ \bottomrule
\end{tabular}

enter image description here

1
  • You should compensate the lack of vertical padding of horizontal rules in the last two solutions, say with cellspace.
    – Bernard
    Commented Jan 14, 2021 at 0:21
4

If you actually want to draw vertical rules compatible with the rules of booktabs (\toprule, bottomrule, \midrule, etc.), although this is not at all in the spirit of booktabs, you should use {NiceTabular} of nicematrix.

\documentclass{article}
\usepackage{nicematrix}
\usepackage{booktabs}

\begin{document}

\begin{table}
\centering
   \begin{NiceTabular}{|c|c|} \toprule
    A & 0.002s \\ 
    B & 0.05s \\
    C & \\ \bottomrule
   \end{NiceTabular}
\caption{}
\end{table}

\end{document}

You need several compilations (because nicematrix uses PGF/Tikz nodes).

Output of the above code

1

As already mentioned tables rules defined in the booktabs are not intended for use with vertical lines.

If you like to have table where vertical in horizontal rules are connected and also horizontal have different thickness and some vertical distance from cells' contents, you can achieve this by use of the makecell package which provide a way to add more vertical space around cells contents as well to define horizontal rules of different thickness:

\documentclass{article}
\usepackage{makecell}

\begin{document}
    \begin{table}
    \centering
    \setcellgapes{3pt}
    \makegapedcells    % <---
\begin{tabular}{|c|c|} 
    \Xhline{1pt}       % <---
A & 0.002s \\
B & 0.05s \\
C & \\
    \Xhline{1pt}
\end{tabular}
\caption{My lovely table}
\label{tab:mlt}
    \end{table}
\end{document}

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .