Tabular ignoring optional parameter to \\
\\
inside a table is defined via \@tabularcr
. If there is an optional argument with positive length, the macro takes the default depth of the line, adds the length and sets an invisible rule with the larger depth.
However, the problematic lines have already a much larger depth because of top-aligned two line cells. As a result, the optional argument remains ineffective unless its length is increased to become larger than the (unknown) depth of the two line cells.
Macro \addlinespace
of package booktabs
uses a different method by inserting the space after the row.
Example:
\documentclass{article}
%% --------------------- These two for \rowcolor (to reproduce image)
\usepackage[table]{xcolor}
\usepackage{array}% For \extrarowheight
\usepackage{booktabs}% For \addlinespace, \defauladdspace
\newcommand{\ShortText}{Short text.}% Fits on one line
\newcommand{\LongText}{Long text that takes up more than one line.}%
\begin{document}
\noindent
\setlength{\defaultaddspace}{2ex}%
\begin{tabular}{l p{0.35\linewidth} p{0.45\linewidth}}
Num & Column 1 & Column 2 \\\addlinespace
1 & \ShortText & \ShortText \\\addlinespace
2 & \ShortText & \LongText \\\addlinespace
\rowcolor{red!25}% <-- Needs xcolor with option table
3 & \LongText & \ShortText \\\addlinespace
4 & \LongText & \LongText \\\addlinespace
5 & \ShortText & \ShortText \\
\end{tabular}
\end{document}
The reason for the different implementation is that the method of LaTeX's \@tabularcr
supports vertical rules. Macro \addlinespace
on the other side comes from package booktabs
for tables without vertical rules.
Adding a spacing with the optional parameter works fine for one-line rows. If there are more lines in a row cell, you have to change the value.
A better solution consists in using the \cellspacetop-bottomlimit
lengths from package cellspace
, which defines a minimal vertical spacing at the top and bottom of cells in columns with specifier prefixed with the letter S
(or C
if you load siunitx
). By definition, this spacing is added only if necessary.
Unrelated : if you load xcolor
with option [table]
, you don't have to load yourself colortbl
.
\documentclass{article}
\usepackage{cellspace}
\setlength{\cellspacebottomlimit}{1ex}
\setlength{\cellspacetoplimit}{1ex}
\usepackage{array}% For \extrarowheight
\newcommand{\ShortText}{Short text.}% Fits on one line
\newcommand{\LongText}{Long text that takes up more than one line.}%
\begin{document}
\noindent
\begin{tabular}{l S{p{0.35\linewidth}} S{p{0.45\linewidth}}}
Num & Column 1 & Column 2 \\
1 & \ShortText & \ShortText \\
2 & \ShortText & \LongText \\
3 & \LongText & \ShortText \\ % <--- Why this optional parameter ignored
4 & \LongText & \LongText \\
5 & \ShortText & \ShortText
\end{tabular}
\vskip1cm
\begin{tabular}{l p{0.35\linewidth} p{0.45\linewidth}}
Num & Column 1 & Column 2 \\[2.0ex]
1 & \ShortText & \ShortText \\[2.0ex]
2 & \ShortText & \LongText \\[4.5ex]
3 & \LongText & \ShortText \\[4.5ex]% <--- Why this optional parameter ignored
4 & \LongText & \LongText \\[2.0ex]
5 & \ShortText & \ShortText \\[2.0ex]
\end{tabular}
\end{document}