3

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

24
  • 2
    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 '21 at 15:42
  • 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 '21 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 '21 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 '21 at 16:12
9

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}

enter image description here

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:

enter image description here

10
  • Running this code gives this error: ! Undefined control sequence. <recently read> \UseTblrLibrary l.28 \UseTblrLibrary {booktabs} ?
    – Math
    Dec 6 '21 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.
    – Zarko
    Dec 6 '21 at 14:28
  • I don't know what version I have, how can I check?
    – Math
    Dec 6 '21 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.
    – Zarko
    Dec 6 '21 at 15:00
  • I still don't get a log file. I am using MikTex.
    – Math
    Dec 6 '21 at 15:34
7

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

c

\documentclass{article}
\usepackage{booktabs}

\usepackage{nicematrix} % added <<<<<<<<<<<<<<<<<<<<<<<<<<<<<

\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
3
  • I tried this and it didn't work. Check Edit.
    – Math
    Dec 2 '21 at 16:07
  • Can you add vertical lines at the beginning and at the end in the second table?
    – Math
    Dec 2 '21 at 16:39
  • 1
    @Math I did. Also added some instructions to try the package without installing it. Dec 2 '21 at 16:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.