我想自定义\section
样式以获得以下标题(忘记水平线):
我认为我需要修改以下定义:
\renewcommand*{\section}[1]{%
\par\addvspace{2.5ex}%
\phantomsection{}% reset the anchor for hyperrefs
\addcontentsline{toc}{section}{#1}%
\strut\sectionstyle{#1}%
{\color{color1}\hrule}%
\par\nobreak\addvspace{1ex}\@afterheading}
我使用的代码是:
\section{CORE COMPETENCIES}
你能告诉我怎么做吗?
答案1
以下是使用\colorbox
和 a 的一种可能性\parbox
:
\documentclass{moderncv}
\moderncvtheme{classic}
\firstname{John}
\familyname{Doe}
\makeatletter
\renewcommand*{\sectionstyle}[1]{\colorbox{color1}{%
\parbox[t]{\dimexpr\textwidth-2\fboxsep\relax}{\sectionfont#1}}}
\renewcommand*{\section}[1]{%
\par\addvspace{2.5ex}%
\phantomsection{}% reset the anchor for hyperrefs
\addcontentsline{toc}{section}{#1}%
\strut\sectionstyle{#1}%
\par\nobreak\addvspace{1ex}\@afterheading}
\makeatother
\begin{document}
\makecvtitle
\section{CORE COMPETENCIES}
\end{document}
也许这种修改更准确地遵循了问题中的图像(彩色框和文本之间没有水平空间和粗体文本);我还添加\MakeUppercase
了\sectionstyle
:
\documentclass{moderncv}
\moderncvtheme{classic}
\firstname{John}
\familyname{Doe}
\makeatletter
\renewcommand\sectionfont{\bfseries\large}
\renewcommand*{\sectionstyle}[1]{{%
\setlength\fboxsep{0pt}%
\colorbox{color1}{%
\parbox[t]{\textwidth}{\sectionfont\rule[-.5ex]{0pt}{2.8ex}\MakeUppercase{#1}}}}}
\renewcommand*{\section}[1]{%
\par\addvspace{2.5ex}%
\phantomsection{}% reset the anchor for hyperrefs
\addcontentsline{toc}{section}{#1}%
\sectionstyle{#1}%
\par\nobreak\addvspace{1ex}\@afterheading}
\makeatother
\begin{document}
\makecvtitle
\section{Core competencies}
\end{document}