# How to draw a vertical line in a table?

How do I draw a vertical line in the following table:

\documentclass{article}
\usepackage{booktabs}
\begin{document}
\noindent\begin{tabular}{lp{1.5in}lp{1.5in}}
\toprule
Parameter & Description & Parameter & Description\\
\midrule
$A$ & Recruitment rate of the population & $B$ & Transmission coefficient\\
\bottomrule
\end{tabular}
\end{document}


In other words I'm trying to get something like the following

parameter meaning | parameter meaning

a pressure| b volatility

c constant| t time

EDIT:

I tried:

\noindent\begin{NiceTabular}{lp{1.5in}|lp{1.5in}}
\toprule
Parameter & Description & Parameter & Description\\
\midrule
$\mu$ & Influx rate of the population & $\epsilon$ & Progression rate from $I_1$ to $I_2$ \\
$\beta_1$ & Transmission rate of the fast latent compartment & $p_1$ & Progression rate from $I_2$ to $J$ \\
$\beta_2$ & Transmission rate of the symptomatic compartment & $p_2$ & Progression rate from $J$ to $A$ \\
$\beta_3$ & Transmission rate of the AIDS compartment & $\xi_1$ & Treatment rate from $J$ to $I_1$ \\
$p$ & Fraction of S infected by $I_2$ who enter $I_1$ & $\xi_2$ & Treatment rate from $J$ to $I_2$ \\
$q$ & Fraction of S infected by $J$ who enter $I_1$ & $\nu$ & Natural death rate \\
$r$ & Fraction of S infected by $A$ who enter $I_1$ & $\alpha$ & Disease related death rate \\
\bottomrule
\end{NiceTabular}


It gave me an error

EDIT 2 :

Zarko, can you compile the following code in your solution so I can use it as an image in my document :

\noindent\begin{tblr}{colspec = {| Q[c,$] X[l] | Q[c,$] X[l] |},
row{1} = {mode=text},
row{2-Y} = {belowsep+=2pt}
}
\toprule
Parameter & Approximate value & Parameter & Approximate value\\
\midrule
\mu     & 0.55
& \epsilon  & 0.002  \\
\beta_1 & 0.0001
& p_1       & 0.01    \\
\beta_2 & 0.006
& p_2       & 0.03      \\
\beta_3 & 0.0007
& \xi_1     & Varying      \\
p       & Varying
& \xi_2     & Varying      \\
q       & Varying
& \nu       & 0.01                    \\
r       & Varying
& \alpha    & 0.01            \\
\bottomrule
\end{tblr}


EDIT 3:

The pdf one looks far better as its less "bulky", so how can I achieve this?

• you can use | but it will be broken at the bookatb rules. Read the booktabs manual for the rules on using vertical rules in tables, Dec 2, 2021 at 15:42
• Dec 2, 2021 at 15:44
• the edit does not provide a usable test document so we can not run what you did and you have given no indication of what error or output that you got. Dec 2, 2021 at 16:09
• @DavidCarlisle It said ! LaTeX Error: Environment NiceTabular undefined. See the LaTeX manual or LaTeX Companion for explanation. Type H <return> for immediate help. ... l.3155 \noindent\begin{NiceTabular} But I already loaded the package
– Math
Dec 2, 2021 at 16:10
• you need to load a new enough nicematrix package or just believe the booktabs manual that stresses that vertical lines are an evil that should never be inflicted on the reader. Dec 2, 2021 at 16:12

UPDATED After follow-up question: solutions do not compile. (see bellow)

Vertical lines can be drawn without conflict with booktabs using the nicematrix package.

The second table has a better alignment of the cells. Uses X columns to adjust their relative widths and centering.

The only package needed to add is nicematrix https://ctan.org/pkg/nicematrix?lang=en

\documentclass{article}
\usepackage{booktabs}

\begin{document}

\noindent\begin{NiceTabular}{lp{1.5in}|lp{1.5in}}
\toprule
Parameter & Description & Parameter & Description\\
\midrule
$\mu$ & Influx rate of the population & $\epsilon$ & Progression rate from $I_1$ to $I_2$ \\
$\beta_1$ & Transmission rate of the fast latent compartment & $p_1$ & Progression rate from $I_2$ to $J$ \\
$\beta_2$ & Transmission rate of the symptomatic compartment & $p_2$ & Progression rate from $J$ to $A$ \\
$\beta_3$ & Transmission rate of the AIDS compartment & $\xi_1$ & Treatment rate from $J$ to $I_1$ \\
$p$ & Fraction of S infected by $I_2$ who enter $I_1$ & $\xi_2$ & Treatment rate from $J$ to $I_2$ \\
$q$ & Fraction of S infected by $J$ who enter $I_1$ & $\nu$ & Natural death rate \\
$r$ & Fraction of S infected by $A$ who enter $I_1$ & $\alpha$ & Disease related death rate \\
\bottomrule
\end{NiceTabular}

\bigskip

\noindent\begin{NiceTabular}[width=\textwidth]{|X[c,m] X[2,l,m] | X[c,m] X[2,l,m] |}[cell-space-limits=3pt]
\toprule
Parameter & Description & Parameter & Description\\
\midrule
$\mu$ & Influx rate of the population & $\epsilon$ & Progression rate from $I_1$ to $I_2$ \\
$\beta_1$ & Transmission rate of the fast latent compartment & $p_1$ & Progression rate from $I_2$ to $J$ \\
$\beta_2$ & Transmission rate of the symptomatic compartment & $p_2$ & Progression rate from $J$ to $A$ \\
$\beta_3$ & Transmission rate of the AIDS compartment & $\xi_1$ & Treatment rate from $J$ to $I_1$ \\
$p$ & Fraction of S infected by $I_2$ who enter $I_1$ & $\xi_2$ & Treatment rate from $J$ to $I_2$ \\
$q$ & Fraction of S infected by $J$ who enter $I_1$ & $\nu$ & Natural death rate \\
$r$ & Fraction of S infected by $A$ who enter $I_1$ & $\alpha$ & Disease related death rate \\
\bottomrule
\end{NiceTabular}

\end{document}


To try the last version of nicematrix without installing it:

1. Download nicematrix.zip from nicematrix.zip
2. Extract the directory nicematrix.
3. Open a command windows in that directory and execute pdflatex nicematrix.ins.
4. The file nicematrix.sty will be generated.
5. Copy that file to your working directory and compile your table

UPDATE Check the version of the packages

Try this code to check the version of the packages

The output will produce two very similar tables, the first using tabularray (from Zarko's answer) and the second with nicematrix

    \documentclass{article}
\usepackage{geometry}
\usepackage{tabularray}
\UseTblrLibrary{booktabs}
\usepackage{nicematrix}

\begin{document}
\parindent0pt

{\large \textbf{tabularray}}\bigskip

\begin{tblr}{colspec = {@{} Q[c,$] X[l] | Q[c,$] X[l] @{}},
row{1} = {mode=text},
row{2-Y} = {belowsep+=2pt}
}
\toprule
Parameter & Description & Parameter & Description\\
\midrule
\mu     & Influx rate of the popu\-la\-tion
& \epsilon  & Progression rate from $I_1$ to $I_2$  \\
\beta_1 & Transmission rate of the fast latent compartment
& p_1       & Progression rate from $I_2$ to $J$    \\
\beta_2 & Transmission rate of the symptomatic compartment
& p_2       & Progression rate from $J$ to $A$      \\
\beta_3 & Transmission rate of the AIDS compartment
& \xi_1     & Treatment rate from $J$ to $I_1$      \\
p       & Fraction of S infected by $I_2$ who enter $I_1$
& \xi_2     & Treatment rate from $J$ to $I_2$      \\
q       & Fraction of S infected by $J$ who enter $I_1$
& \nu       & Natural death rate                    \\
r       & Fraction of S infected by $A$ who enter $I_1$
& \alpha    & Disease related death rate            \\
\bottomrule
\end{tblr}

\bigskip

{\large \textbf{nicematrix}}\bigskip

\begin{NiceTabular}{cp{2.0in}|cp{2.0in}}[cell-space-limits=4pt]
\toprule
Parameter & Description & Parameter & Description\\
\midrule
$\mu$ & Influx rate of the population & $\epsilon$ & Progression rate from $I_1$ to $I_2$ \\
$\beta_1$ & Transmission rate of the fast latent compartment & $p_1$ & Progression rate from $I_2$ to $J$ \\
$\beta_2$ & Transmission rate of the symptomatic compartment & $p_2$ & Progression rate from $J$ to $A$ \\
$\beta_3$ & Transmission rate of the AIDS compartment & $\xi_1$ & Treatment rate from $J$ to $I_1$ \\
$p$ & Fraction of S infected by $I_2$ who enter $I_1$ & $\xi_2$ & Treatment rate from $J$ to $I_2$ \\
$q$ & Fraction of S infected by $J$ who enter $I_1$ & $\nu$ & Natural death rate \\
$r$ & Fraction of S infected by $A$ who enter $I_1$ & $\alpha$ & Disease related death rate \\
\bottomrule
\end{NiceTabular}

\end{document


If it fails run the following code

    \listfiles % list the files loaded <<<<<<<<<<<<<<
\documentclass{article}
\usepackage{geometry}
\usepackage{tabularray}
\UseTblrLibrary{booktabs}
\usepackage{nicematrix}

\begin{document}

Only to list the files loaded

\end{document}


Important See that before \documentclass{article} there is the command \listfiles

Now look at the end of the .log file.

You should see a list of all files loaded, similar to

*File List*
article.cls    2020/04/10 v1.4m Standard LaTeX document class
size10.clo    2020/04/10 v1.4m Standard LaTeX file (size option)
geometry.sty    2020/01/02 v5.9 Page Geometry
....

epstopdf-base.sty    2020-01-24 v2.11 Base part for package epstopdf
epstopdf-sys.cfg    2021/03/18 v2.0 Configuration of epstopdf for MiKTeX
***********


On my current system it appears

tabularray.sty    2021-12-01 v2021Q Typeset tabulars and arrays with LaTeX3

nicematrix.sty    2021/09/09 v6.2 Enhanced arrays with the help of PGF/TikZ


If in your case the versions installed are previous, I suggest you update them.

I am using the MiKTeX distribution, where this task is done using the MiKTeX Console.

Edit 2

• I tried this and it didn't work. Check Edit.
– Math
Dec 2, 2021 at 16:07
• Can you add vertical lines at the beginning and at the end in the second table?
– Math
Dec 2, 2021 at 16:39
• @Math I did. Also added some instructions to try the package without installing it. Dec 2, 2021 at 16:59
• I get this error running the last code: ! Undefined control sequence. <argument> \l_keys_key_str l.4612 ...ormal } { Continued ~ on ~ next ~ page } ?
– Math
Mar 7 at 12:41
• @Math The message is coming from tabularray. Check the version you have installed. I also get pdflatex: security risk: running with elevated privileges This is pdfTeX, Version 3.141592653-2.6-1.40.22 (MiKTeX 21.3). Your system is older? Mar 7 at 12:59

With tabularray package you can simple combine rules from booktabs package and vertical lines. Additional advantage is that final form of table is achieved already after one compilation.

\documentclass{article}
\usepackage{geometry}
\usepackage{tabularray}
\UseTblrLibrary{booktabs}

\begin{document}
\noindent\begin{tblr}{colspec = {@{} Q[c,$] X[l] | Q[c,$] X[l] @{}},
row{1} = {mode=text},
row{2-Y} = {belowsep+=2pt}
}
\toprule
Parameter & Description & Parameter & Description\\
\midrule
\mu     & Influx rate of the popu\-la\-tion
& \epsilon  & Progression rate from $I_1$ to $I_2$  \\
\beta_1 & Transmission rate of the fast latent compartment
& p_1       & Progression rate from $I_2$ to $J$    \\
\beta_2 & Transmission rate of the symptomatic compartment
& p_2       & Progression rate from $J$ to $A$      \\
\beta_3 & Transmission rate of the AIDS compartment
& \xi_1     & Treatment rate from $J$ to $I_1$      \\
p       & Fraction of S infected by $I_2$ who enter $I_1$
& \xi_2     & Treatment rate from $J$ to $I_2$      \\
q       & Fraction of S infected by $J$ who enter $I_1$
& \nu       & Natural death rate                    \\
r       & Fraction of S infected by $A$ who enter $I_1$
& \alpha    & Disease related death rate            \\
\bottomrule
\end{tblr}
\end{document}


In the case, that you like to have vertical lines at begin and end of table too, than the specification of your table should be:

\noindent\begin{tblr}{colspec = {| Q[c,$] X[l] | Q[c,$] X[l] |},
row{1} = {mode=text},
row{2-Y} = {belowsep+=2pt}
}


Using it, the resulted table is:

As you asked me in comment, here is result of compilation of your code. In test I use the following preamble:

\documentclass{article}
\usepackage{geometry}
\usepackage{tabularray}
\UseTblrLibrary{booktabs}


From it follows, that in test are used default font size (10pt) and default fonts (Computer Modern). Image shown here is cutout from screen by Snipping Tool (I use w10 OS), here is shown as png image with default setting of imgur settings.

A "fair" comparison is comparing resulted pdf files, where image are in vector format.

BTW, now I use tabularray package version 2022A (hopefully in few days with recent version 2022B available on CTAN from June 1st ;-). In your case results are the same from version 2021P further).

• Running this code gives this error: ! Undefined control sequence. <recently read> \UseTblrLibrary l.28 \UseTblrLibrary {booktabs} ?
– Math
Dec 6, 2021 at 13:34
• Which version tabularray you have? MWE in my answer is tested by 2021P and it works (no warnings, no errors). I check it again. Dec 6, 2021 at 14:28
• I don't know what version I have, how can I check?
– Math
Dec 6, 2021 at 14:34
• hm, simplest way is try to upgrade your tabularray installation (or better, complete LaTeX installation). However, at begin of your document add \listfiles instruction which will at and of .log file collect all used packages with listed version. There you will see, which version use your system. Dec 6, 2021 at 15:00
• I still don't get a log file. I am using MikTex.
– Math
Dec 6, 2021 at 15:34