paracol默认的分栏线是实线,如何更改为虚线?之前我在网上看到过一份简历好像用tikz实现的,但现在那份简历搜不到了,故请教各位大佬!
\documentclass{ctexart}
\usepackage{zhlipsum}
\usepackage{paracol}
\setlength{\columnseprule}{0.7pt}
\columnratio{0.6}
\begin{document}
\begin{paracol}{2}
\zhlipsum[1]
\switchcolumn
\zhlipsum[2]
\end{paracol}
\end{document}
首先你需要打一个 patch:
\makeatletter
\protected\def\makeparacolrule#1{\def\@pcolmakeparacolrule##1##2{\hb@xt@##2{\hss#1\hss}}}
\makeparacolrule{\vrule\@height#1\@width#2} % 默认, #1:=height, #2:=width
\def\pcol@buildcolseprule#1#2#3#4{%
\@tempdima#1\relax \dimen@#4\relax
\let\pcol@bg@from#2\relax \let\pcol@bg@to#3\relax
\setbox\pcol@tempboxa\vbox{}\setbox\@tempboxa\vbox{}%
\let\@elt\pcol@buildcselt@S \pcol@sptextlist
\@tempdimb\z@ \let\@elt\pcol@buildcselt \pcol@sptextlist
\let\@elt\relax \advance\@tempdima-\@tempdimb
\ifdim\@tempdima>\z@
\setbox\pcol@tempboxa\vbox{\unvbox\pcol@tempboxa
\nointerlineskip
\vbox{\@pcolmakeparacolrule{\@tempdima}{\columnseprule}\vss}}%
\setbox\@tempboxa\vbox{\unvbox\@tempboxa
\let\@elt\relax
\edef\pcol@bg@columntop{\number\@tempdimb sp}%
\edef\pcol@bg@columnheight{%
\@elt{\number\@tempdima sp}\@elt{\number\dimen@ sp}}%
\pcol@bg@paintcolumns}%
\fi}
\def\pcol@buildcselt#1#2{%
\@tempdimc#1sp \advance\@tempdimc-\@tempdimb
\setbox\pcol@tempboxa\vbox{\unvbox\pcol@tempboxa
\ifdim\@tempdimc>\z@
\nointerlineskip
\vbox{\@pcolmakeparacolrule{\@tempdimc}{\columnseprule}\vss}%
\fi
\vskip#2sp}%
\setbox\@tempboxa\vbox{\unvbox\@tempboxa
\let\@elt\relax
\edef\pcol@bg@columntop{\number\@tempdimb sp}%
\edef\pcol@bg@columnheight{\@elt{\number\@tempdimc sp}}%
\ifdim\@tempdimc>\z@ \pcol@bg@paintcolumns \fi
\def\pcol@bg@spanningtop{\@elt{#1sp}}%
\advance\@tempdima-#1sp\relax \advance\@tempdima-#2sp\relax
\advance\dimen@\@tempdima
\edef\pcol@bg@spanningheight{\@elt{#2sp}%
\ifdim\@tempdima>\z@\else \@elt{\number\dimen@ sp}\fi}%
\pcol@bg@paintbox{s}}%
\@tempdimb#1sp \advance\@tempdimb#2sp\relax}
\makeatother
或者直接 patch:
\usepackage{etoolbox}
\makeatletter
\protected\def\makeparacolrule#1{\def\@pcolmakeparacolrule##1##2{\hb@xt@##2{\hss#1\hss}}}
\makeparacolrule{\vrule\@height#1\@width#2} % 默认, #1:=height, #2:=width
\patchcmd\pcol@buildcolseprule{\hrule\@height\@tempdima\@width\columnseprule}
{\nointerlineskip\vbox{\@pcolmakeparacolrule{\@tempdima}{\columnseprule}\vss}}{}{\err}
\patchcmd\pcol@buildcselt{\hrule\@height\@tempdimc\@width\columnseprule}
{\nointerlineskip\vbox{\@pcolmakeparacolrule{\@tempdimc}{\columnseprule}\vss}}{}{\err}
\makeatother
它是把原来划线的命令替换为 \@pcolmakeparacolrule
,然后可以用 \makeparacolrule{...}
来画自己的命令。
\usepackage{tikz}
% #1:=height, #2:=width
\makeparacolrule{\tikz\draw[dashed,line width=#2](0pt,0pt)--(0pt,#1);}
完整代码:
\documentclass{ctexart}
\usepackage{zhlipsum}
\usepackage{paracol}
\setlength{\columnseprule}{0.7pt}
\columnratio{0.6}
\usepackage{etoolbox}
\makeatletter
\protected\def\makeparacolrule#1{\def\@pcolmakeparacolrule##1##2{\hb@xt@##2{\hss#1\hss}}}
\makeparacolrule{\vrule\@height#1\@width#2} % 默认, #1:=height, #2:=width
\patchcmd\pcol@buildcolseprule{\hrule\@height\@tempdima\@width\columnseprule}
{\nointerlineskip\vbox{\@pcolmakeparacolrule{\@tempdima}{\columnseprule}\vss}}{}{\err}
\patchcmd\pcol@buildcselt{\hrule\@height\@tempdimc\@width\columnseprule}
{\nointerlineskip\vbox{\@pcolmakeparacolrule{\@tempdimc}{\columnseprule}\vss}}{}{\err}
\makeatother
\usepackage{tikz}
\begin{document}
\makeparacolrule{\tikz\draw[dashed,line width=#2](0pt,0pt)--(0pt,#1);}
\begin{paracol}{2}
\zhlipsum[1]
\switchcolumn
\zhlipsum[2]
\end{paracol}
\end{document}
啊,这么复杂!
仔细看,其实也不复杂,感谢大佬!
@u7483 它的画线命令包装在其它命令中,需要修改整个命令。或者使用
\patchcmd
来修改。见更新。