# Ruled section and \dotfill'ed subsection heading

I am using the memoir class and would like to recreate the section and subsection headings from the moderncv "banking" style:

I was able to create the rule under the section heading using the following:

\newcommand{\ruledsec}[1]{%
\Large\bfseries\raggedright\strut #1%
\hrule%
}
\setaftersecskip{.5\onelineskip}


However, the following subsection style will break the \dotfill into a new line:

\newcommand{\dottedsubsec}[1]{%
\large\bfseries\raggedright\strut #1%
\scriptsize\dotfill%
}
\setaftersubsecskip{.25\onelineskip}


How can I achieve the desired effect? Is there maybe an easier way to style the headings?

Two solutions.

One approach is to make the afterskip negative, so the dots are run-in to the heading text. The afterskip dimension then specifies a horizontal skip, which you should set to 0pt. The vertical spacing then needs to be added after the \dotsfill; unfortunately \vspace and \vspace* get discarded, so either you need to use \\[...]

\newcommand{\dottedsubsec}[1]{%
\large\bfseries\strut #1%
\dotfill\\[0.25\onelineskip]
}


or, probably better, place the title and dots in a box:

\newcommand{\dottedsubsec}[1]{%
\noindent\parbox{\textwidth}{\large\bfseries\strut #1%
\dotfill}\vspace{0.25\onelineskip}%
}


\documentclass{memoir}

\newcommand{\ruledsec}[1]{%
\Large\bfseries\raggedright\strut #1%
\hrule%
}
\setaftersecskip{.5\onelineskip}

\newcommand{\dottedsubsec}[1]{%
\noindent\parbox{\textwidth}{\large\bfseries\strut #1%
\dotfill}\vspace{0.25\onelineskip}%
}
\setaftersubsecskip{-0pt}

\begin{document}

\section*{Experience}
\subsection*{Vocational}
Text.

\end{document}


A second approach, which behaves better with respect following lists in your situation, is as follows. While making the after skip negative solves the run-in problem, it invokes quite a different branch of the \@startsection code. Keeping the after skip positive, one can work around the corresponding coding by killing a \@@par command in the \@startsection code preventing a line break after the title; the code below does this within in a group to localise the effect:

\makeatletter
\newcommand{\dottedsubsec}[1]{%
{\noindent\let\@@par\relax\large\bfseries\strut #1%
\dotfill}
}
\makeatother


\documentclass{memoir}

\newcommand{\ruledsec}[1]{%
\Large\bfseries\raggedright\strut #1%
\hrule%
}
\setaftersecskip{.5\onelineskip}

\makeatletter
\newcommand{\dottedsubsec}[1]{%
{\noindent\let\@@par\relax\large\bfseries\strut #1%
\dotfill}
}
\makeatother
\setaftersubsecskip{0.25\onelineskip}

\begin{document}

\showoutput

\section*{Experience}
Text.
\subsection*{Vocational}
Text.

\section*{Experience}
\begin{description}
\item[Test] test
\end{description}

\subsection*{Vocational}
\begin{description}
\item[Test] test
\end{description}

\end{document}

• That works for adding the dotted line, thanks! However I am getting too much spacing if there's e.g. a list directly below the subsection. Any ideas how I could fix the spacing so that there's no extra line break? – user53911 Sep 5 '15 at 15:22
• The updated version is exactly what I was looking for. The look of moderncv is recreated perfectly when using \scriptsize\dotfill}% instead of the \dotfill} line. Cheers – user53911 Sep 5 '15 at 17:50