自动缩放垂直规则以适合文本高度

自动缩放垂直规则以适合文本高度

我正在尝试修改包中各部分的样式moderncv。具体来说,我希望各部分在部分文本高度的右侧有一个垂直规则。以下是无效的代码,其中规则的高度是硬编码的:

\documentclass[11pt,sans]{moderncv}
\moderncvstyle{casual}
\moderncvcolor{blue}
\reversemarginpar
\usepackage[paper=letterpaper,
             marginparwidth=1.2in,
             marginparsep=.05in,
             margin=1in,
             includemp,
             scale=0.75]{geometry}
\setlength{\parindent}{0in}

\renewcommand{\section}[1]{\pagebreak[3]%
    \vspace{1.3\baselineskip}%
    \phantomsection\addcontentsline{toc}{section}{#1}%
    \noindent\llap{\scshape\smash{\parbox[t]{%
        \marginparwidth}{%
            \hyphenpenalty=10000\raggedright%
            \sectionfont{\textcolor{color1}{#1 \rule{1pt}{18pt}}}}}}%
    \vspace{-\baselineskip}\par}

% personal data
\name{Harry}{Potter}
\title{Resumé}
\address{Hogwarts}
\phone[mobile]{+777~(0)~777-777777}

\usepackage[utf8]{inputenc}
\title{}
\begin{document}

\makecvtitle

\section{Technology Summary}
\label{sec:orgheadline7}

\subsection{Languages}
\label{sec:orgheadline1}
ActionScript, C, Clojure, Common Lisp, Emacs Lisp, Erlang, Forth, Haskell,
Haxe, Java, JavaScript, Mercury, OCaml, PHP, Prolog, Python, Ruby, Scala,
Scheme, Shell.

\end{document}

我想我需要以\parbox某种方式引用先前声明的内容,但我不知道该怎么做。

以下图片说明了这个问题:

在此处输入图片描述

答案1

这是一个使用tikzmarkTikZ 的库(由于进行了内部计算,代码需要运行两到三次才能使规则达到最终位置):

\documentclass[11pt,sans]{moderncv}
\moderncvstyle{casual}
\moderncvcolor{blue}
\usepackage{tikz}
\usetikzlibrary{tikzmark}
\reversemarginpar
\usepackage[paper=letterpaper,
             marginparwidth=1.2in,
             marginparsep=.05in,
             margin=1in,
             includemp,
             scale=0.75]{geometry}
\setlength{\parindent}{0in}

\newcounter{tmp}

\renewcommand{\section}[1]{\pagebreak[3]%
    \stepcounter{tmp}%
    \par\vspace{1.3\baselineskip}%
    \phantomsection\addcontentsline{toc}{section}{#1}%
    \noindent\llap{\scshape\smash{\parbox[t]{%
        \dimexpr\marginparwidth-5pt\relax}{%
            \hyphenpenalty=10000\raggedright%
            \sectionfont{\textcolor{color1}{\tikzmark{start-\thetmp}#1\hfill\tikzmark{end-\thetmp}}}}}}%
            \tikz[remember picture,overlay]
              \draw[color1,line width=1pt] ([xshift=5pt,yshift=2ex]{pic cs:end-\thetmp}|-{pic cs:start-\thetmp}) -- ([xshift=5pt]{pic cs:end-\thetmp});
    \vspace{-\baselineskip}\par}

\usepackage[utf8]{inputenc}
\firstname{John}
\familyname{Doe}
\title{}
\begin{document}

\section{A test section}
\cventry{2008--2010}{Lecturer}{Some Place}{Some Country}{}{Some responsabilities} 

\section{Another test section}
\cventry{2008--2010}{Lecturer}{Some Place}{Some Country}{}{Some responsabilities} 

\section{Yet another test section with a longer title}
\cventry{2008--2010}{Lecturer}{Some Place}{Some Country}{}{Some responsabilities} 

\end{document}

结果:

在此处输入图片描述

答案2

您只需使用tabular

\documentclass[11pt,sans,draft]{moderncv}
\moderncvstyle{casual}
\moderncvcolor{blue}
\reversemarginpar
\usepackage[paper=letterpaper,
             marginparwidth=1.3in,
             marginparsep=.05in,
             margin=1in,
             includemp,
             scale=0.75]{geometry}
\setlength{\parindent}{0in}

\renewcommand{\section}[1]{\pagebreak[3]%
    \vspace{1.3\baselineskip}%
    \phantomsection\addcontentsline{toc}{section}{#1}%
    \noindent\raisebox{-0\height}[0pt][0pt]{\llap{%
    \color{color1}\renewcommand\arrayrulewidth{1pt}%
    \begin{tabular}[t]{@{}>{\hyphenpenalty=10000\raggedright}p{\marginparwidth}|}
       \textcolor{color1}{\sectionfont{#1}}
       \end{tabular}
       }}%
    \vspace{-\baselineskip}\par}

% personal data
\name{Harry}{Potter}
\title{Resumé}
\address{Hogwarts}
\phone[mobile]{+777~(0)~777-777777}

\usepackage[utf8]{inputenc}
\title{}
\begin{document}

\makecvtitle

\section{A test section}
\cventry{2008--2010}{Lecturer}{Some Place}{Some Country}{}{Some responsabilities}

\section{Another test section}
\cventry{2008--2010}{Lecturer}{Some Place}{Some Country}{}{Some responsabilities}

\section{Yet another test section with a longer title}
\cventry{2008--2010}{Lecturer}{Some Place}{Some Country}{}{Some responsabilities}


\end{document}

在此处输入图片描述

相关内容