0

I used the following code to create a table:

\begin{tabular}{p{3cm}|p{3cm}|p{3cm}} 
  Symbol & Units & Quantity     \\  
\hline \hline
    $A$                 & m$^2$   & Area         \\
    $a$                 & m^{2}/s & Acceleration \\
    $F$                 & N       & Force        \\
    $l$                 & m       & Length       \\
    $u$                 & m/s     & Velocity
\end{tabular}

The output of which is:

enter image description here

As one can see, the vertical lines are not continuous i.e., when the vertical lines meet the horizontal lines there is a gap and again after the second horizontal line the vertical lines become continuous.

I do not want the gap in the vertical lines. I want something as depicted in the following picture:

enter image description here

Can someone please tell me what changes I should make in my code to achieve the desired result?

7
  • Replace \hline\hline with \hhline{=|=|=} and add the hhline package to your preamble.
    – leandriis
    Mar 27, 2020 at 7:55
  • Could you please make your code compilable? Currently, your table will throw an error message upon compiling due to m^{2}/s in the second row of the table. Also, the spacing around the rows seems to be different from what you show in your output.
    – leandriis
    Mar 27, 2020 at 8:07
  • 1
    I would not even use vertical lines at all. And I'd use the the lines from booktabs. And use siunitx to format units.
    – daleif
    Mar 27, 2020 at 8:11
  • 1
    I prefer tables without vertical bars :-)
    – Zarko
    Mar 27, 2020 at 8:11
  • 2
    Just out of curiosity: When did u become the symbol for velocity? When I was young, the universally-used symbol was v, not u...
    – Mico
    Mar 27, 2020 at 9:13

2 Answers 2

4

To get the desired continuous vertical line, you can use \hhline{=|=|=} from the hhline package. In the following example, I have also used the siunitx package for the units.

In the following mwe, I have added three versions of the table. In the first one I just added \hhline and siunitx. Here, the exponent touches the horizontal line. To prevent that, I hav´ve added the second table in which I have additionally used the cellspace package for some white space around the cells. Personally, I would however prefer a more compact table without vertical lines and the horizontal lines of the booktabs package. An example for that is shown in the third table:

enter image description here

\documentclass{article}
\usepackage{hhline}
\usepackage{siunitx}
\sisetup{per-mode=symbol}
\usepackage[column=0]{cellspace}
\setlength\cellspacetoplimit{3pt}
\setlength\cellspacebottomlimit{\cellspacetoplimit}
\usepackage{booktabs}

\begin{document}

\begin{tabular}{p{3cm}|p{3cm}|p{3cm}} 
  Symbol & Units & Quantity     \\  
\hhline{=|=|=}
    $A$                 & \si{\m\squared}       & Area         \\
    $a$                 & \si{\m\squared\per\s} & Acceleration \\
    $F$                 & \si{\N}               & Force        \\
    $l$                 & \si{\m}               & Length       \\
    $u$                 & \si{\m\per\s}         & Velocity
\end{tabular}

\bigskip

\begin{tabular}{0{p{3cm}}|0{p{3cm}}|0{p{3cm}}} 
  Symbol & Units & Quantity     \\  
\hhline{=|=|=}
    $A$                 & \si{\m\squared}       & Area         \\
    $a$                 & \si{\m\squared\per\s} & Acceleration \\
    $F$                 & \si{\N}               & Force        \\
    $l$                 & \si{\m}               & Length       \\
    $u$                 & \si{\m\per\s}         & Velocity
\end{tabular}

\bigskip

\begin{tabular}{lll} 
\toprule
  Symbol & Units & Quantity     \\  
\midrule
    $A$                 & \si{\m\squared}       & Area         \\
    $a$                 & \si{\m\squared\per\s} & Acceleration \\
    $F$                 & \si{\N}               & Force        \\
    $l$                 & \si{\m}               & Length       \\
    $u$                 & \si{\m\per\s}         & Velocity     \\
\bottomrule
\end{tabular}
\end{document}
3
  • the units touch the hline
    – js bibra
    Mar 27, 2020 at 8:05
  • +1 for the booktabs-based alternative. :-)
    – Mico
    Mar 27, 2020 at 9:07
  • Incidentally, I would use v rather than u as the symbol for velocity.
    – Mico
    Mar 27, 2020 at 9:14
0

With {NiceTabular} of nicematrix, you have directly the expected output (however, a design of the table with booktabs is probably better).

\documentclass{article}
\usepackage{nicematrix}

\begin{document}

\begin{NiceTabular}{p{3cm}|p{3cm}|p{3cm}}[cell-space-top-limit=2pt]
  Symbol & Units & Quantity     \\  
\hline \hline
    $A$                 & m$^2$     & Area         \\
    $a$                 & m$^{2}$/s & Acceleration \\
    $F$                 & N         & Force        \\
    $l$                 & m         & Length       \\
    $u$                 & m/s       & Velocity
\end{NiceTabular}

\end{document}

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

Output of the above code

You must log in to answer this question.

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