文本行内的水平线

文本行内的水平线

您可能知道,moderncv每个部分的左侧都有一条水平线。我也想将其打印在部分标题的右侧,就像这样:

期望输出的模型

我当前的代码如下:

\documentclass[10pt,a4paper]{moderncv}
\moderncvtheme[blue]{classic}
\usepackage[T1]{fontenc}
\usepackage[utf8x]{inputenc}
\usepackage[english]{babel}
\usepackage[scale=0.92]{geometry}

\setlength{\hintscolumnwidth}{1.2cm}
\usepackage{helvet}

\firstname{\Huge Johnson}
\familyname{Green\vspace{-3mm}}

\title{\normalsize \color{black}Expertise in xxx and xxx.}
\mobile{\color{black}{\textbf{(987) 1234 5678}}}
\email{[email protected]}

\begin{document}
\maketitle

\section{\textbf{\textsc{Objective}}}
Seeking the XXX position in YYY that ... 

\section{\textbf{\textsc{Education}}}
\cvitem{2010 - 2014}{ Ph.D, Z University}
\cvitem{2006 - 2010}{ B.A, M University}
\end{document}

答案1

您可以重新定义\section以添加规则:

\documentclass{moderncv}
\moderncvstyle{classic}
\moderncvcolor{blue}
\usepackage[T1]{fontenc}
\usepackage[utf8x]{inputenc}
\usepackage[english]{babel}
\usepackage[scale=0.92]{geometry}
\usepackage{helvet}

\setlength{\hintscolumnwidth}{1.2cm}
\newlength\TitleWd
\newlength\LeftRuleWd

\makeatletter
\RenewDocumentCommand{\section}{sm}{%
  \settowidth\TitleWd{\sectionstyle{#2}}%
\setlength\LeftRuleWd{%
  \dimexpr\textwidth-\TitleWd-2\separatorcolumnwidth-\hintscolumnwidth\relax}%
  \par\addvspace{2.5ex}%
  \phantomsection{}% reset the anchor for hyperrefs
  \addcontentsline{toc}{section}{#2}%
  \parbox[t]{\hintscolumnwidth}{\strut\raggedleft\raisebox{\baseletterheight}{\color{color1}\rule{\hintscolumnwidth}{0.95ex}}}%
  \hspace{\separatorcolumnwidth}%
  \parbox[t]{\TitleWd}{\strut\sectionstyle{#2}}%
  \hspace{\separatorcolumnwidth}%
  \parbox[t]{\LeftRuleWd}{\strut\raggedleft\raisebox{\baseletterheight}{\color{color1}\rule{\LeftRuleWd}{0.95ex}}}%  
  \par\nobreak\addvspace{1ex}\@afterheading}% to avoid a pagebreak after the heading
\makeatother

\name{John}{Doe}

\begin{document}

\section{Objective}
Test text and some more text and some more text and some more text and some more text and some more text and some more text and some more text and some more text and some more text and some more text and some more text
\section{Another title}
Test text and some more text and some more text and some more text and some more text and some more text and some more text and some more text and some more text and some more text and some more text and some more text

\end{document}

在此处输入图片描述

答案2

还有更简单的解决方案:

\let\sectionOri=\section
\def\section#1{\sectionOri{#1 \ \leaders\hrule height7.1pt depth-1.8pt \hfill}}

当然,如果您需要生成目录,此解决方案将无法正常工作。但我希望此应用程序不需要目录。

相关内容