0

I would like to give a custom style to my table of contents, in a memoir document.

My goal is to make it look like in the image below, more specifically underline the entire line for sections and nothing for subsections, instead of having dots like with the default style:

what I would like to do

I know the tocloft package can be used to some extent, but I didn't find how to use it to do that. I saw someone mixing its use with tikz figures but I hope there is an easier way to do it.

4
  • Welcome to TeX.SX! Please add a small but compilable example document to your questions that show how yout ToC currently looks like and that can be used as a basis for the modifications you want.
    – siracusa
    Commented Sep 17, 2019 at 23:09
  • Just out of curiosity, where is the line suppose to be if the entry is multilined?
    – daleif
    Commented Sep 18, 2019 at 9:09
  • @daleif under the second line (if what you mean is: when the chapter title needs to be written on more than one line)
    – Seldi
    Commented Sep 18, 2019 at 10:43
  • Then that is easy in memoir, see my answer
    – daleif
    Commented Sep 18, 2019 at 11:05

2 Answers 2

1

This is pretty simple with titletoc:

\documentclass[a4paper,twoside french]{book}
\usepackage[utf8]{inputenc}
\usepackage{fourier, erewhon}
\usepackage{titletoc}
\usepackage{lipsum}

\renewcommand{\thesubsection}{\thesection\,\alph{subsection})}
\titlecontents{chapter}
[0em] %
{\bigskip\sffamily\bfseries\large}
{\thecontentslabel.\enspace}%numbered chapters
{}%unnumbered chapters
{\hfill\contentspage}[\hrule\smallskip]

\titlecontents{section}
[1.8em] %
{\smallskip\sffamily\bfseries\normalsize}
{\thecontentslabel.\enspace}%\thecontentslabel
{}
{\hfill\contentspage}%[\hrule\medskip]

\titlecontents{subsection}
[4.1em] %
{\smallskip\sffamily\normalsize}
{\thecontentslabel\enspace}%
{}
{\hfill\contentspage}%

\begin{document}

\tableofcontents

\chapter{Introduction}
    \section{Sec1}
        \lipsum
    \section{Sec2}
        \lipsum
\chapter{Premier paragraphe}
    \section{Premier sous-paragraphe}
        \lipsum
    \section{Deuxième sous-paragraphe}
        \lipsum
\chapter{Deuxième paragraphe}
    \section{Premier sous-paragraphe}
        \subsection{Première sous-section}
        \subsection{Deuxième sous-section}
        \lipsum
    \section{Deuxième sous-paragraphe}
    \section*{Conclusion du deuxième paragraphe}\addcontentsline{toc}{section}{Conclusion du deuxième paragraphe}

\chapter{Conclusion}

\end{document} 

enter image description here

1

In memoir this can be done with a one-liner

\renewcommand{\cftchapterafterpnum}{\par\smallskip\hrule\par\smallskip}

We basically look at the pseudocode for how ToC entries are build. At the end we have \cftchapterafterpnum\par. By default \cftchapterafterpnum is empty. So we use it to insert our own stuff after the page number. Just remember to start it with \par such that the line is a paragraph on its own.

This has not been optimised against page breaks.

1
  • This one also works, and is more simple
    – Seldi
    Commented Sep 18, 2019 at 14:33

You must log in to answer this question.

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