3

I'm trying to add a vertical space in a table after each row. Currently I have the following files where the spacing works.

My main file:

% table-sep.tex
\documentclass{table-sep}

\begin{document}

\begin{tabularcv}
    \hline
    2012-2016   &   Some text here which is a bit long \\
    \hline
    2010-2012   &   More text here \\
    \hline
\end{tabularcv}

\end{document}

My working class file:

% table-sep.cls
\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{table-sep}[2017/08/03 custom class v1]
\LoadClass[a4paper]{article}

\RequirePackage{tabularx} 

\RequirePackage{cellspace}
\cellspacebottomlimit 30pt

% New environment with two columns
\newenvironment{tabularcv}{%
    \tabularx{\textwidth}{%
        @{}>{\raggedright\arraybackslash}S{p{2.5 cm}}%
        @{}>{\raggedright\arraybackslash}Sl%
    }%
}%
{\endtabularx}%

Result Working situation

However if I load the xcolor package by adding \RequirePackage{xcolor} to my .cls file, \cellspacebottomlimit has no effect. Or if I change the right column from a l to a p{} column in my .cls file:

@{}>{\raggedright\arraybackslash}Sl%

into

@{}>{\raggedright\arraybackslash}S{p{5 cm}}%

\cellspacebottomlimit has no effect either. I then get:

Not working

Non-working class file

% table-sep.cls
\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{table-sep}[2017/08/03 custom class v1]
\LoadClass[a4paper]{article}

\RequirePackage{tabularx} 

\RequirePackage{cellspace}
\cellspacebottomlimit 30pt

% New environment with two columns
\newenvironment{tabularcv}{%
    \tabularx{\textwidth}{%
        @{}>{\raggedright\arraybackslash}S{p{2.5 cm}}%
        @{}>{\raggedright\arraybackslash}S{p{5 cm}}%
    }%
}%
{\endtabularx}%

\RequirePackage{xcolor} %

Edit 9 August 2017

As mentioned in my comment I've tried the same in one .tex file. With this code, if the package xcolor is used, it will disable \cellspacebottomlimit. If tried to place \usepackage{xcolor} at various parts in the preamble, but it gave the same result. Also with this code, the part S{p{5 cm}} does not disable the workings of \cellspacebottomlimit.

Code

%table-sep-v2.tex
\documentclass[a4paper]{article}

\usepackage{tabularx} 

\usepackage{cellspace}
\cellspacebottomlimit 30pt

% New environment with two columns
\newenvironment{tabularcv}{%
    \tabularx{\textwidth}{%
        @{}>{\raggedright\arraybackslash}S{p{2.5 cm}}%
        @{}>{\raggedright\arraybackslash}S{p{5 cm}}%
    }%
}%
{\endtabularx}%

% \usepackage{xcolor} % Uncommenting this will disable the space set by \cellspacebottomlimit

\begin{document}

\begin{tabularcv}
    \hline
    2012-2016   &   Some text here which is a bit long \\
    \hline
    2010-2012   &   More text here \\
    \hline
\end{tabularcv}

\end{document}
  • Why do you make testing more difficult by splitting your example into two files? – Ulrike Fischer Aug 3 '17 at 17:35
  • @UlrikeFischer Well my original problem this was the case. It did not occur to me to try it in one file. I can update the question. – Roald Aug 3 '17 at 17:40
  • @UlrikeFischer I just tried it with one file, by loading the packages with \usepackage. In this case enabling xcolor causes \cellspacebottomlimit to have no effect (just as previously). However, now @{}>{\raggedright\arraybackslash}S{p{5 cm}} does not disable \cellspacebottomlimit. – Roald Aug 3 '17 at 17:45
  • Just color suffices in order to show the problem. – egreg Aug 9 '17 at 10:59
3

The problem arises when color is loaded, because it makes \color@endgroup into a real group closing macro. In cellspace.sty we find

\renewcommand*{\@endpbox}{%
      \unless \ifcellspace@
        \@finalstrut \@arstrutbox
      \fi
      \par
      % Save the depth of the last line
      \global \cellspace@lastdp = \prevdepth
      \color@endgroup
      % \ifcellspace@ is only locally true, so we need to expand it before
      % \egroup stops it action
      \expandafter
    \egroup
    \ifcellspace@
    <irrelevant code here>

but in the case color is loaded, \color@endgroup already ends the effect of \cellspace@true. Solution: add another \expandafter before \color@endgroup.

\documentclass[a4paper]{article}

\usepackage{color,xpatch}

\usepackage{cellspace}
\setlength{\cellspacebottomlimit}{30pt}

\makeatletter
\xpatchcmd{\@endpbox}{\color@endgroup}{\expandafter\color@endgroup}{}{\ddt}
\makeatother

% New environment with two columns
\newenvironment{tabularcv}{%
    \par\noindent
    \begin{tabular}{
        @{}>{\raggedright\arraybackslash}S{p{2.5 cm}}
        @{}>{\raggedright\arraybackslash}S{p{\dimexpr\textwidth-2.5cm\relax}}
        @{}
    }
}
{\end{tabular}}


\begin{document}

\begin{tabularcv}
    \hline
    2012-2016   &   Some text here which is a bit long \\
    \hline
    2010-2012   &   More text here \\
    \hline
\end{tabularcv}

\end{document}

I also changed tabularx into tabular: it makes no sense to use the former without an X column and, moreover, the documentation of cellspace explicitly says it has not been tested with tabularx.

enter image description here

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.