I would like to move the page number from the right-hand side of a table of contents to the left, using tocloft
. The page number should still be right-aligned.
The question has already been answered here for titletoc
, but I would like to know if there is a way to achieve the same using tocloft
. The question referred to suggests not, but I would like to check anyway.
I start with a MWE:
\documentclass[a4paper]{article}
\usepackage{lipsum}
\RequirePackage[titles]{tocloft}
\makeatletter
\renewcommand{\cftsecpresnum}{\begin{lrbox}{\@tempboxa}}
\renewcommand{\cftsecaftersnum}{\end{lrbox}}
\setlength{\cftsecnumwidth}{0pt}
\makeatother
\begin{document}
\tableofcontents
\section{Section 1 title}
\lipsum[1-2]
\section{Section 2 title}
\lipsum[3-4]
\end{document}
That produces this:
I am trying to move the page numbers to the other side:
And in case you're wondering, this is what I'm actually trying to achieve (without the blue lines). I've done the rest of the formatting successfully using tocloft
, which is why I would prefer to continue using that package rather than switching to titletoc
.
Best Answer
This update achieves right alignment, as explained in my added comment. The defect is that it will not work if
\thepage
is not the standard representation with digits. Also the placement of the page number is not so good in the case of multiline section titles.Without hacking
tocloft
internal redefinition of\l@section
I don't think there is a way. Here is an attempt though. DefectsWith package etoc one may obtain all of your layout.