我想在moderncv
类中添加子部分,该子部分以符号(例如项目符号或圆圈)或其他与布局协调的符号开头moderncv
。或者我如何绘制\hline
(并使用相同的背景颜色)?
我已经读过了如何在“moderncv”类中使用子部分?,但这不是我要找的。
我有类似的东西
使用代码:
\documentclass[11pt,a4paper,sans]{moderncv}
\moderncvstyle{casual}
\moderncvcolor{grey}
\usepackage{lipsum}
\usepackage[scale=0.75]{geometry}
\firstname{xxx}
\familyname{xxx}
\title{Research Statement}
\begin{document}
\makecvtitle
\section{Section}
\subsection{Subsection}
\lipsum
\end{document}
但是,我想要这样的东西
答案1
\section
那么,命令和\subsection
风格的定义casual
是
\RenewDocumentCommand{\section}{sm}{%
\par\addvspace{2.5ex}%
\phantomsection{}% reset the anchor for hyperrefs
\addcontentsline{toc}{section}{#2}%
\cvitem[0ex]{\strut\raggedleft\raisebox{\baseletterheight}{\color{color1}\rule{\hintscolumnwidth}{0.95ex}}}{\strut\sectionstyle{#2}}%
\par\nobreak\addvspace{1ex}\@afterheading}% to avoid a pagebreak after the heading
\RenewDocumentCommand{\subsection}{sm}{%
\par\addvspace{1ex}%
\phantomsection{}% reset the anchor for hyperrefs
\addcontentsline{toc}{subsection}{#2}%
\cvitem[0ex]{}{\strut\subsectionstyle{#2}}%
\par\nobreak\addvspace{.5ex}\@afterheading}% to avoid a pagebreak after the heading
现在我们可以创建一个新命令\mysubsection
来获取您想要的内容。我刚刚将水平规则的命令添加到命令中,其长度为\hintscolumnwidth
命令的一半,并删除了命令的使用\cvitem
,它为规则和文本构建了两列:
\makeatletter
\NewDocumentCommand{\mysubsection}{sm}{%
\par\addvspace{1ex}%
\phantomsection{}% reset the anchor for hyperrefs
\addcontentsline{toc}{subsection}{#2}%
{\strut\raggedleft\raisebox{\baseletterheight}{\color{color1}\rule{0.5\hintscolumnwidth}{0.95ex}}\quad}{\strut\subsectionstyle{#2}}%
\par\nobreak\addvspace{.5ex}\@afterheading}% to avoid a pagebreak after the heading
\makeatother
因为上面的代码中使用了命令\makeatletter
和,\makeatother
所以需要它们。@
拥有完整的 MWE
\documentclass[11pt,a4paper,sans]{moderncv}
\moderncvstyle{casual} % head [left,right] 2, body 1, foot 1
\moderncvcolor{grey}
\usepackage{lipsum}
\usepackage[scale=0.75]{geometry}
\makeatletter
\NewDocumentCommand{\mysubsection}{sm}{%
\par\addvspace{1ex}%
\phantomsection{}% reset the anchor for hyperrefs
\addcontentsline{toc}{subsection}{#2}%
{\strut\raggedleft\raisebox{\baseletterheight}{\color{color1}\rule{0.5\hintscolumnwidth}{0.95ex}}\quad}{\strut\subsectionstyle{#2}}%
\par\nobreak\addvspace{.5ex}\@afterheading}% to avoid a pagebreak after the heading
\makeatother
\firstname{John}
\familyname{Doe}
\title{Research Statement}
\begin{document}
\makecvtitle
\section{Section}
\subsection{Subsection}
\lipsum[1]
\mysubsection{Subsection}
\lipsum[1]
\end{document}
得到结果: