xcolor 包禁用 cellspace 包

xcolor 包禁用 cellspace 包

我正在尝试在表格中添加垂直空间每行。目前我有以下文件,其中间距有效。

我的主要文件:

% 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}

我的工人阶级档案:

% 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}%

结果 工作情况

但是,如果我xcolor通过添加\RequirePackage{xcolor}到我的.cls文件来加载包,\cellspacebottomlimit则没有任何效果。或者如果我将文件中的右列从 a 列更改l为 a列:p{}.cls

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

进入

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

\cellspacebottomlimit也没有任何效果。然后我得到:

不工作

非工薪阶层档案

% 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} %

编辑于 2017 年 8 月 9 日

正如我所提到的评论我在一个文件中尝试了同样的方法。使用此代码,如果使用.tex包,它将禁用。如果尝试放置在序言中的各个部分,但结果相同。同样使用此代码,部分确实xcolor\cellspacebottomlimit\usepackage{xcolor}S{p{5 cm}}不是禁用 的工作原理\cellspacebottomlimit

代码

%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}

答案1

color加载时会出现问题,因为它会\color@endgroup变成真正的组关闭宏。cellspace.sty我们发现

\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>

color但在已加载的情况下,\color@endgroup已经结束了的效果。解决方案:在之前\cellspace@true添加另一个。\expandafter\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}

我也改成了tabularxtabular在没有列的情况下使用前者是没有意义的X,而且的文档cellspace明确说它没有经过测试tabularx

在此处输入图片描述

相关内容