# Spacing and vertical lines on a tabularx

I made a table with tabular with the following code:

\documentclass[12pt,a4paper]{article}

\begin{document}
\begin{table}[ht!]\centering\begin{tabular}{|c|c|c|c|}

\hline Regulator&$K_p$&$T_i$&$T_d$\\

\hline P&$\displaystyle{}\frac{\displaystyle{}1+\frac{0,35\tau}{1-\tau}}a$&&\\

\hline PI&$\displaystyle{}\frac{\displaystyle{}0,9(1+\frac{0,92\tau}{1-\tau})}a$&$\displaystyle{}\frac{(3,3-3\tau)L}{1+1,2\tau}$&\\

\hline PD&$\displaystyle{}\frac{\displaystyle{}1,24(1+\frac{0,13\tau}{1-\tau})}a$&&$\displaystyle{}\frac{(0,27-0,36\tau)L}{1-0,87\tau}$\\

\hline PID&$\displaystyle{}\frac{\displaystyle{}1,35(1+\frac{0,18\tau}{1-\tau})}a$&$\displaystyle{}\frac{(2,5-2\tau)L}{1-0,39\tau}$&$\displaystyle{}\frac{(0,37-0,37\tau)L}{1-0,81\tau}$\\\hline

\end{tabular}\caption{Determinarea parametriilor regulatorului PID prin metoda Cohen-Coon\cite{CohenCoon}}\end{table}
\end{document}


, but I have gotten the table which the text is near the horizontal line.

Then I tried with

\documentclass[12pt,a4paper]{article}
\usepackage{tabularx}

\usepackage{ragged2e}

\newcolumntype{L}[1]{>{\RaggedRight\hspace{0pt}\hsize=#1\hsize}X}

\usepackage{booktabs}
\begin{document}
\begin{table}[ht!]\centering\begin{tabularx}{\textwidth}{@{} *{3}{L{0.8}} L{1.6} @{}}

\toprule Regulator&$K_p$&$T_i$&$T_d$\\

\midrule\addlinespace P&$\displaystyle{}\frac{\displaystyle{}1+\frac{0,35\tau}{1-\tau}}a$&&\\

\midrule\addlinespace PI&$\displaystyle{}\frac{\displaystyle{}0,9(1+\frac{0,92\tau}{1-\tau})}a$&$\displaystyle{}\frac{(3,3-3\tau)L}{1+1,2\tau}$&\\

\midrule\addlinespace PD&$\displaystyle{}\frac{\displaystyle{}1,24(1+\frac{0,13\tau}{1-\tau})}a$&&$\displaystyle{}\frac{(0,27-0,36\tau)L}{1-0,87\tau}$\\

\midrule\addlinespace PID&$\displaystyle{}\frac{\displaystyle{}1,35(1+\frac{0,18\tau}{1-\tau})}a$&$\displaystyle{}\frac{(2,5-2\tau)L}{1-0,39\tau}$&$\displaystyle{}\frac{(0,37-0,37\tau)L}{1-0,81\tau}$\\\midrule

\end{tabularx}\caption{Determinarea parametriilor regulatorului PID prin metoda Cohen-Coon\cite{CohenCoon}}\end{table}
\end{document}


, but there is not a vertical line between columns, and some formulas are lower than others, as shown in the image below.

The questions are how do I fix the formulas to be on the same level and how do I add a vertical line between columns?

• Welcome! You cannot use vertical rules with booktabs. Or you can, but the result will look awful. For an explanation, read booktabs documentation. Professional quality tables don't use vertical rules, so booktabs doesn't support them. So, the question is whether you want professional-quality tables or whether you want vertical lines .... Either way, please edit your question to make your code compile.
– cfr
Commented May 18 at 18:18
• unrelated but don't use {} after \displaystyle it will adversely affect the spacing Commented May 18 at 19:00

Professional quality tables don't use vertical rules, as explained in booktabs documentation, so, unless you're doing something special, I'd omit them.

\begin{table}[ht!]
\centering
\begin{tabularx}{\textwidth}{@{} *{3}{L{0.8}} L{1.6} @{}}
\toprule
Regulator&$K_p$&$T_i$&$T_d$\\
\midrule
P&$\displaystyle \frac{\displaystyle 1+\frac{0,35\tau}{1-\tau}}a$&&\\
PI&$\displaystyle \frac{\displaystyle 0,9(1+\frac{0,92\tau}{1-\tau})}a$&$\displaystyle \frac{(3,3-3\tau)L}{1+1,2\tau}$&\\
PD&$\displaystyle \frac{\displaystyle 1,24(1+\frac{0,13\tau}{1-\tau})}a$&&$\displaystyle \frac{(0,27-0,36\tau)L}{1-0,87\tau}$\\
PID&$\displaystyle \frac{\displaystyle 1,35(1+\frac{0,18\tau}{1-\tau})}a$&$\displaystyle \frac{(2,5-2\tau)L}{1-0,39\tau}$&$\displaystyle \frac{(0,37-0,37\tau)L}{1-0,81\tau}$\\
\bottomrule
\end{tabularx}
\caption{Determinarea parametriilor regulatorului PID prin metoda Cohen-Coon\cite{CohenCoon}}
\end{table}


Note the use of \bottomrule.

Your code was also generating overfull horizontal boxes due to a problem with the definition of L. I modified that definition and redefined the X column to use baseline alignment rather than the default top.

\newcolumntype{L}[1]{>{\hsize=#1\hsize\linewidth=\hsize}X}
\renewcommand \tabularxcolumn[1]{W{c}{#1}}


Note that \RaggedRight is pointless here as LaTeX can't hyphenate the mathematics anyway, so I removed that.

If you really must have vertical lines, despite reading booktabs on the subject, you can improve things a little bit with this:

\begin{table}[ht!]
\centering
\setlength \extrarowheight {5ex}
\begin{tabular}{|c|c|c|c|}
\hline
Regulator&$K_p$&$T_i$&$T_d$\\
\firsthline
P&$\displaystyle \frac{\displaystyle 1+\frac{0,35\tau}{1-\tau}}a$&&\\
\hline
PI&$\displaystyle \frac{\displaystyle 0,9(1+\frac{0,92\tau}{1-\tau})}a$&$\displaystyle \frac{(3,3-3\tau)L}{1+1,2\tau}$&\\
\hline
PD&$\displaystyle \frac{\displaystyle 1,24(1+\frac{0,13\tau}{1-\tau})}a$&&$\displaystyle \frac{(0,27-0,36\tau)L}{1-0,87\tau}$\\
\hline
PID&$\displaystyle \frac{\displaystyle 1,35(1+\frac{0,18\tau}{1-\tau})}a$&$\displaystyle \frac{(2,5-2\tau)L}{1-0,39\tau}$&$\displaystyle \frac{(0,37-0,37\tau)L}{1-0,81\tau}$\\
\lasthline
\end{tabular}
\caption{Determinarea parametriilor regulatorului PID prin metoda Cohen-Coon\cite{CohenCoon}}
\end{table}


but you had better use one of the newer packages in this case such as tabularray or the older makecell.

Complete code:

\documentclass{article}
\usepackage{tabularx}
\newcolumntype{L}[1]{>{\centering\arraybackslash\hsize=#1\hsize\linewidth=\hsize}X}
\renewcommand \tabularxcolumn[1]{W{c}{#1}}
\usepackage{booktabs}
\begin{document}
\pagestyle{empty}%
\begin{table}[ht!]
\centering
\setlength \extrarowheight {5ex}
\begin{tabular}{|c|c|c|c|}
\hline
Regulator&$K_p$&$T_i$&$T_d$\\
\firsthline
P&$\displaystyle \frac{\displaystyle 1+\frac{0,35\tau}{1-\tau}}a$&&\\
\hline
PI&$\displaystyle \frac{\displaystyle 0,9(1+\frac{0,92\tau}{1-\tau})}a$&$\displaystyle \frac{(3,3-3\tau)L}{1+1,2\tau}$&\\
\hline
PD&$\displaystyle \frac{\displaystyle 1,24(1+\frac{0,13\tau}{1-\tau})}a$&&$\displaystyle \frac{(0,27-0,36\tau)L}{1-0,87\tau}$\\
\hline
PID&$\displaystyle \frac{\displaystyle 1,35(1+\frac{0,18\tau}{1-\tau})}a$&$\displaystyle \frac{(2,5-2\tau)L}{1-0,39\tau}$&$\displaystyle \frac{(0,37-0,37\tau)L}{1-0,81\tau}$\\
\lasthline
\end{tabular}
\caption{Determinarea parametriilor regulatorului PID prin metoda Cohen-Coon\cite{CohenCoon}}
\end{table}

\begin{table}[ht!]
\centering
\begin{tabularx}{\textwidth}{@{} *{3}{L{0.8}} L{1.6} @{}}
\toprule
Regulator&$K_p$&$T_i$&$T_d$\\
\midrule
P&$\displaystyle \frac{\displaystyle 1+\frac{0,35\tau}{1-\tau}}a$&&\\
PI&$\displaystyle \frac{\displaystyle 0,9(1+\frac{0,92\tau}{1-\tau})}a$&$\displaystyle \frac{(3,3-3\tau)L}{1+1,2\tau}$&\\
PD&$\displaystyle \frac{\displaystyle 1,24(1+\frac{0,13\tau}{1-\tau})}a$&&$\displaystyle \frac{(0,27-0,36\tau)L}{1-0,87\tau}$\\
PID&$\displaystyle \frac{\displaystyle 1,35(1+\frac{0,18\tau}{1-\tau})}a$&$\displaystyle \frac{(2,5-2\tau)L}{1-0,39\tau}$&$\displaystyle \frac{(0,37-0,37\tau)L}{1-0,81\tau}$\\
\bottomrule
\end{tabularx}
\caption{Determinarea parametriilor regulatorului PID prin metoda Cohen-Coon\cite{CohenCoon}}
\end{table}

\end{document}


• +1. :-) I've taken the liberty of uploading a higher-resolution screenshot.
– Mico
Commented May 19 at 5:09
• @Mico Thank-you, but I wish I could figure it out to do it myself!
– cfr
Commented May 19 at 6:17
• I know about the rule "Professional tables do not use vertical lines" I do not disagree and keep to the booktabs style myself whenever I can. However I am wondering why vertical lines in tables are applied so persistently in general. Commented May 22 at 2:39
• @JohannesLinkels Word processors? They aren't applied persistently in books which contain tables or journal articles.
– cfr
Commented May 22 at 2:59
• @cfr Aahhh didn't think about Word Processors. Might very well be true as primary focus is not on creating professional documents. Although it is advertised differently. And yes, it takes some effort to remove the vertical lines from a table in the Word processors I know. Or in spreadsheets. Commented May 22 at 12:16

In addition to getting rid of all vertical rules and replacing all instances of \hline with the appropriate macros of the booktabs package, I would also declutter the code by placing columns 2 thru 4 in automatic math mode and defining a helper macro called \ddfrac ("double displaystyle \frac"). Furthermore, I'd load the icomma package to fix the spacing around the decimal-marker commas, and I'd enlarge the parentheses in the numerator terms in column 1. Optionally, load the threeparttable macro so that the width of the caption doesn't exceed that of the tabular environment.

\documentclass[12pt,a4paper]{article}
\usepackage[T1]{fontenc}
\usepackage[romanian]{babel}
\usepackage{array}   % for '\newcolumntype' macro
\usepackage{amsmath} % for '\dfrac' macro
\usepackage{icomma}
\usepackage{booktabs}% for well-spaced horizontal rules
\usepacakge{threeparttable} % for 'threeparttable' env.
\newcolumntype{C}{>{$}c<{$}} % automatic math mode
\newcommand\ddfrac[2]{\dfrac{\displaystyle #1}{\displaystyle #2}}

\begin{document}

\begin{table}[ht!]
\begin{threeparttable}
\centering
\begin{tabular}{@{} l CCC @{}}
\toprule
Regulator& K_p & T_i & T_d \\
\midrule
P        & \ddfrac{1+\frac{0,35\tau}{1-\tau}}a
&
& \\
PI       & \ddfrac{0,9\Bigl(1+\frac{0,92\tau}{1-\tau}\Bigr)}{a}
& \ddfrac{(3,3-3\tau)L}{1+1,2\tau}
& \\
PD       & \ddfrac{1,24\Bigl(1+\frac{0,13\tau}{1-\tau}\Bigr)}{a}
&
& \ddfrac{(0,27-0,36\tau)L}{1-0,87\tau}\\
PID      & \ddfrac{1,35\Bigl(1+\frac{0,18\tau}{1-\tau}\Bigr)}{a}
& \ddfrac{(2,5-2\tau)L}{1-0,39\tau}
& \ddfrac{(0,37-0,37\tau)L}{1-0,81\tau}\\
\bottomrule
\end{tabular}
\caption{Determinarea parametriilor regulatorului PID prin
metoda Cohen-Coon\cite{CohenCoon}}
\end{threeparttable}
\end{table}

\end{document}


With {NiceTabular} of nicematrix, you have a key cell-spaces-limits to address that issue.

\documentclass[12pt,a4paper]{article}
\usepackage{caption}
\usepackage{nicematrix}
\NiceMatrixOptions{cell-space-limits=3pt}

\begin{document}

\begin{table}[ht!]
\centering
\begin{NiceTabular}{cccc}%
[
hvlines ,
caption = Determinarea parametriilor regulatorului PID prin metoda Cohen-Coon\cite{CohenCoon}
]
Regulator&$K_p$&$T_i$&$T_d$\\
P&$\displaystyle{}\frac{\displaystyle{}1+\frac{0,35\tau}{1-\tau}}a$&&\\
PI&$\displaystyle{}\frac{\displaystyle{}0,9(1+\frac{0,92\tau}{1-\tau})}a$&$\displaystyle{}\frac{(3,3-3\tau)L}{1+1,2\tau}$&\\
PD&$\displaystyle{}\frac{\displaystyle{}1,24(1+\frac{0,13\tau}{1-\tau})}a$&&$\displaystyle{}\frac{(0,27-0,36\tau)L}{1-0,87\tau}$\\
PID&$\displaystyle{}\frac{\displaystyle{}1,35(1+\frac{0,18\tau}{1-\tau})}a$&$\displaystyle{}\frac{(2,5-2\tau)L}{1-0,39\tau}$&$\displaystyle{}\frac{(0,37-0,37\tau)L}{1-0,81\tau}$\\
\end{NiceTabular}
\end{table}

\end{document}


Of course, I recommend a style in the spirit of \booktabs and the rules of booktabs (\toprule, \midrule).

\documentclass[12pt,a4paper]{article}
\usepackage{caption}
\usepackage{booktabs}
\usepackage{nicematrix}
\NiceMatrixOptions{cell-space-limits=5pt}

\begin{document}

\begin{table}[ht!]
\centering
\begin{NiceTabular}{@{}lccc@{}}%
[ caption = Determinarea parametriilor regulatorului PID prin metoda Cohen-Coon\cite{CohenCoon} ]
\toprule
Regulator&$K_p$&$T_i$&$T_d$\\
\midrule
P&$\displaystyle{}\frac{\displaystyle{}1+\frac{0,35\tau}{1-\tau}}a$&&\\
PI&$\displaystyle{}\frac{\displaystyle{}0,9(1+\frac{0,92\tau}{1-\tau})}a$&$\displaystyle{}\frac{(3,3-3\tau)L}{1+1,2\tau}$&\\
PD&$\displaystyle{}\frac{\displaystyle{}1,24(1+\frac{0,13\tau}{1-\tau})}a$&&$\displaystyle{}\frac{(0,27-0,36\tau)L}{1-0,87\tau}$\\
PID&$\displaystyle{}\frac{\displaystyle{}1,35(1+\frac{0,18\tau}{1-\tau})}a$&$\displaystyle{}\frac{(2,5-2\tau)L}{1-0,39\tau}$&$\displaystyle{}\frac{(0,37-0,37\tau)L}{1-0,81\tau}$\\
\bottomrule
\end{NiceTabular}
\end{table}

\end{document}