1

In a tabular environment, \\[<spacing>] does not always insert the requested spacing between rows containing themselves tabulars. For instance, the two horizontal lines should not be aligned in the example below. The command \\[<spacing>] seems to work only when the spacing requested is larger than the height of the second line.

I have found two solutions:

  1. Insert a void row, i.e. replace \\[5pt] by \\[-12pt]&\\[5pt] (for two columns), where 12pt is the value of \baselineskip;
  2. Replace \\[5pt] by the command \addlinespace[5pt] of the booktabs package.

In his comments to the similar problem mentionned in Vertical skip between p{...} rows of tabular, David Carlisle does not seem very optimistic about this, but still, would it be possible to redefine \\ so that it automatically does the right thing in tabulars, without loading an extra package? Even if there is no solution, it may be worth to ask the question in case some other user faces the same problem...

Example:

\documentclass{article}
\begin{document}
\begin{tabular}[t]{ll}
  a &
  \begin{tabular}[t]{@{}l}
    b \\ c
  \end{tabular}
  \\
  \hline
  d & e
\end{tabular}
\begin{tabular}[t]{ll}
  a &
  \begin{tabular}[t]{@{}l}
    b \\ c
  \end{tabular}
  \\[5pt]
  \hline
  d & e
\end{tabular}
\end{document}
  • the optional argument just lengthens the strut that sets the default space so if your content has more depth than that already it does nothing. If you have no vertical rules then \\\noalign{\vspace{1cm}} will do what you want (that is more or less what the booktabs command is doing), if you do have vertical rules and want to add space without breaking them., it's harder. – David Carlisle Feb 29 '16 at 17:14
  • Indeed, my second solution (with \addlinespace) and yours (with \noalign) break vertical lines. My first solution (void row) doesn't, even if clumsy. – Michel Fioc Mar 1 '16 at 10:28
1

You can have more or less automatic ways, but with some additional packages. Compare these (with cellspace which ensures a minimal vertical padding in columns prefixed with the letter S, the result of \\[5pt] and using booktabs and \midrule, which introduces some padding around rules, which may be customised changing the values of \aboverulesep and \belowrulesep:

\documentclass{article}
\usepackage{array, cellspace, booktabs}
\setlength\cellspacebottomlimit{5pt}

\begin{document}

\mbox{}\hphantom{\texttt{With booktabs}: \quad } \begin{tabular}[t]{lSl}
\multicolumn{2}{>{\ttfamily}c}{with cellspace} \\
  a &
  \begin{tabular}[t]{@{}l}
    b \\ c
  \end{tabular}
  \\
  \hline
  d & e
\end{tabular}
\quad
\begin{tabular}[t]{ll}
\multicolumn{2}{>{\ttfamily}c}{with [5pt]} \\
  a &
  \begin{tabular}[t]{@{}l}
    b \\ c
  \end{tabular}
  \\[5pt]
  \hline
  d & e
\end{tabular}
\vskip1cm
\texttt{With booktabs}: \quad \begin{tabular}[t]{ll}
\multicolumn{2}{>{\ttfamily}c}{default belowrulesep} \\
  a &
  \begin{tabular}[t]{@{}l}
    b \\ c
  \end{tabular}
  \\
  \midrule
  d & e
\end{tabular}
\quad
{ \setlength\aboverulesep{5pt}
\begin{tabular}[t]{ll}
\multicolumn{2}{>{\ttfamily}c}{custom belowrulesep} \\
  a &
  \begin{tabular}[t]{@{}l}
    b \\ c
  \end{tabular}
  \\
  \midrule
  d & e
\end{tabular}}

\end{document} 

enter image description here

  • The solution with cellspace works with vertical lines too. – Michel Fioc Mar 1 '16 at 10:38
  • Yes. That said, in general vertical rules don't look very professional. – Bernard Mar 1 '16 at 10:40

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.