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.



\thepageprints out arabic numbers. The idea is to redefine\cftsecpagefontto be something like\global\acountwith\acounta count registers. Then\cftsecafterpnumwill do the page number placement: the advantage is that we can get it right aligned then, however it will still be difficult to position it higher up in case of multiline section name. – Apr 04 '14 at 18:06tocloft, only with plain tex (see the tugboat toc for the relevant example). see whether it's possible to reorder the pieces that go into a toc line, setting the page number as the first element, followed by the rest, with the text hanging indented to the appropriate distance -- in other words, treating the whole thing as a hanging indented (ragged right) paragraph. – barbara beeton Apr 04 '14 at 18:24etocandLaTeX2eall of this re-shuffling is easy to achieve. The page number is available as\etocpage, the section number as\etocnumber, the section title as\etocname. – Apr 04 '14 at 18:27etoc; it would show the power of the package. On a second thought, the question asks specifically fortocloft, so perhaps this is not the place to show the power ofetoc? – Gonzalo Medina Apr 04 '14 at 18:33toclofttheme. – Apr 04 '14 at 18:45tocloft, as I'd already done all my formatting with that (which took me ages) and I didn't fancy trying to re-do it all intitletocwith the chance that something else wouldn't be supported. However, @jfbu pointed outetoc(which I hadn't heard of) on another question of mine, and I've found that it's actually been fairly quick to customise my TOC as required. I'm almost there, but will come back and have another look at this question shortly. I've been posting my questions separately in order to try and keep things simple. – abeverley Apr 04 '14 at 18:46