我在处理 MWE 时最终回答了自己的问题,但结果很有趣。也许我应该将这个问题重新命名为“为什么\columnsep=0pt
重置 paracol 时会出现错误?”
基本上,我可以轻松地在和之间切换\begin{paracol}{4}
,\begin{paracol{3}
直到我使用\setcolumnwidth
时,每次都必须更改它。我尝试使用\setcolumnwidth{}
并出现错误。但当我将它添加到我的 MWE 时,它就起作用了!
事实证明,仅当您设置时才会发生错误\columnsep=0pt
。
\documentclass{article}
\usepackage{paracol}
\parindent=0pt
\begin{document}
\begin{paracol}{4}
\rule{\columnwidth}{1ex}
\switchcolumn
\rule{\columnwidth}{1ex}
\switchcolumn
\rule{\columnwidth}{1ex}
\switchcolumn
\rule{\columnwidth}{1ex}
\end{paracol}
\begin{paracol}{3}
\rule{\columnwidth}{1ex}
\switchcolumn
\rule{\columnwidth}{1ex}
\switchcolumn
\rule{\columnwidth}{1ex}
\end{paracol}
\setcolumnwidth{\dimexpr 0.25\textwidth-0.75\columnsep}% set globally
\begin{paracol}{2}
\rule{\columnwidth}{1ex}
\switchcolumn
\rule{\columnwidth}{1ex}
\switchcolumn
\end{paracol}%
\setcolumnwidth{}% rset column widths
\begin{paracol}{3}
\rule{\columnwidth}{1ex}
\switchcolumn
\rule{\columnwidth}{1ex}
\switchcolumn
\rule{\columnwidth}{1ex}
\end{paracol}
should match second row
\setlength{\columnsep}{0pt}
\setcolumnwidth{0.25\textwidth}% set globally
\begin{paracol}{2}
\rule{\columnwidth}{1ex}
\switchcolumn
\rule{\columnwidth}{1ex}
\switchcolumn
\end{paracol}%
\setcolumnwidth{}
Will get error here
\begin{paracol}{3}
\rule{\columnwidth}{1ex}
\switchcolumn
\rule{\columnwidth}{1ex}
\switchcolumn
\rule{\columnwidth}{1ex}
\end{paracol}
\end{document}
答案1
添加一些颜色有助于阐明问题。
即使设置\columnnsep
为非常小的值以避免列和间隙宽度计算中的溢出错误(有关详细信息,请参阅手册第 7.3 节),结果也是错误的:绿线缺失,正如您从最后一行看到的那样。
冲突是由于设置\setcolumnwidth{0pt}
重新设置列宽而引起的,这是没有必要的。
回答你的问题标题:
该命令对列宽的设置将在该命令之后的 paracol 环境中生效。因此,虽然将该命令放在前言中是最自然的方式,但您可以将该命令放在两个 paracol 环境之间,以更改第二个环境的列布局,即使它们出现在一个页面中。
总之,\columnnsep = 0pt
没有引发任何错误。
\documentclass[12pt]{article}
\usepackage{paracol}
\usepackage{xcolor}
\parindent=0pt
\begin{document}
{\Large New code}
\begin{paracol}{4}
\color{green}\rule{\columnwidth}{1ex}
\switchcolumn
\color{red}\rule{\columnwidth}{1ex}
\switchcolumn
\color{blue}\rule{\columnwidth}{1ex}
\switchcolumn
\color{black}\rule{\columnwidth}{1ex}
\end{paracol}
\begin{paracol}{3}
\color{green}\rule{\columnwidth}{1ex}
\switchcolumn
\color{red}\rule{\columnwidth}{1ex}
\switchcolumn
\color{blue}\rule{\columnwidth}{1ex}
\end{paracol}
\bigskip
\setcolumnwidth{\dimexpr 0.25\textwidth-0.75\columnsep}% set globally
\begin{paracol}{2}
\color{green}\rule{\columnwidth}{1ex}
\switchcolumn
\color{red}\rule{\columnwidth}{1ex}
\end{paracol}%
% \setcolumnwidth{0pt}% rset column widths WRONG <<<<<<<<<<<<<<<<
\begin{paracol}{3}
\color{green}\rule{\columnwidth}{1ex}
\switchcolumn
\color{red} \rule{\columnwidth}{1ex}
\switchcolumn
\color{blue}\rule{\columnwidth}{1ex}
\end{paracol}
\bigskip
Should match second row with no column separations (YES)
\setcolumnwidth{0.25\textwidth}% set globally
\setlength{\columnsep}{0pt} % is OK <<<
\begin{paracol}{2}
\color{green}\rule{\columnwidth}{1ex}
\switchcolumn
\color{red}\rule{\columnwidth}{1ex}
\end{paracol}%
% \setcolumnwidth{0pt} % reset column widths WRONG <<<<<<<<<<<<<
With columnsep =0pt we will get error here (NO)
\begin{paracol}{3}
\color{green}\rule{\columnwidth}{1ex}
\switchcolumn
\color{red}\rule{\columnwidth}{1ex}
\switchcolumn
\color{blue}\rule{\columnwidth}{1ex}
\end{paracol}
\vspace*{50pt}
{\Large Former code}
Should match second row with no column separations
(Does not happens: missing green rule)
\setcolumnwidth{0.25\textwidth}% set globally
\setlength{\columnsep}{0.02pt} % OK <<<
\begin{paracol}{2}
\color{green}\rule{\columnwidth}{1ex}
\switchcolumn
\color{red}\rule{\columnwidth}{1ex}
\end{paracol}%
\setcolumnwidth{0pt} % rset column widths WRONG <<<<<
Will get error here (only if columnsep=0pt,
but wrong result anyway, even if columnsep=0.02pt)
\begin{paracol}{3}
\color{green}\rule{\columnwidth}{1ex}
\switchcolumn
\color{red}\rule{\columnwidth}{1ex}
\switchcolumn
\color{blue}\rule{\columnwidth}{1ex}
\end{paracol}
\end{document}