我正在尝试在表格中添加垂直空间后每行。目前我有以下文件,其中间距有效。
我的主要文件:
% 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}
我也改成了tabularx
:tabular
在没有列的情况下使用前者是没有意义的X
,而且的文档cellspace
明确说它没有经过测试tabularx
。