如果使paracol的分栏线为虚线

发布于 2022-04-09 20:28:06

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}

查看更多

关注者
0
被浏览
1.2k
雾月
雾月 2022-04-09
这家伙很懒,什么也没写!

首先你需要打一个 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);}

image.png

完整代码:

\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}
1 个回答

撰写答案

请登录后再发布答案,点击登录

发布
问题

分享
好友

手机
浏览

扫码手机浏览