4

I'm writing an article and would like to section it with the same style of modernCV, but cannot find any suggestion.

Can someone help me? =)enter image description here

3
  • Welcome to TeX.SX! Please help us and add a minimal working example (MWE) that shows a basic document and your attempts at solving the question. The horizontal bar can be done with a \rule
    – ienissei
    Apr 27, 2016 at 8:37
  • Package titlesec can do that.
    – Bernard
    Apr 27, 2016 at 9:59
  • If your question is answered, please mark a solution. Apr 30, 2016 at 18:35

1 Answer 1

6

I found this in the sources of moderncv

\strut\raggedleft\raisebox{\baseletterheight}{\color{color1}\rule{\hintscolumnwidth}{0.95ex}}

it creates the box. The full definition for the section is

\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

You just have to replace the cvitem and all the variables.

Edit(This includes all the necessary lengths, you have to insert the color yourself):

\usepackage{xparse}
\makeatletter
\newlength{\hintscolumnwidth} \setlength{\hintscolumnwidth}{0.175\textwidth}
\newlength{\baseletterheight} \settoheight{\baseletterheight}{o}
\newlength{\separatorcolumnwidth} \setlength{\separatorcolumnwidth}{0.025\textwidth}
% fonts
\newcommand*{\sectionfont}{\Large\mdseries\upshape}
% styles
\newcommand*{\sectionstyle}[1]{{\sectionfont{#1}}}
\RenewDocumentCommand{\section}{sm}{%
    \par\addvspace{2.5ex}%
    \addcontentsline{toc}{section}{#2}%
    {\strut\raggedleft\raisebox{\baseletterheight}{\rule{\hintscolumnwidth}{0.95ex}}}\hspace*{\separatorcolumnwidth}{\strut\sectionstyle{#2}}%
    \par\nobreak\addvspace{1ex}\@afterheading}% to avoid a pagebreak after the heading
\makeatother
2
  • I am quite new to latex, so I have to ask you further help if possible. I should copy the text (\RenewDocumentCommand...etc) before \begin{document}. Which variables have I to change and how? Instead of "\cvitem" what should I insert? Sorry for my inexpert questions :) Apr 27, 2016 at 11:12
  • You have to use \usepackage{xparse} and insert the command. You then should remove \cvitem[0ex] and replace the values of \baseletterheight, \hintscolumnwidth, color1, \sectionstyle by whatever they are set to in the original source. And then you have to fiddle around a bit until it's exactly the way you want it.
    – BenjaminH
    Apr 27, 2016 at 11:27

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .