0

I need to create the toc like content, with the multiple page number right aligned like in the below image, text will be left and page number will be ragged left aligned

I tried but failed to get the Page number alone in the right alignment, How to get this output?

enter image description here

MWE:

 \documentclass{book}

\makeatletter
\newdimen\figurecontwidth%
\newskip\enspacefigurecontentwidth\enspacefigurecontentwidth=8.5pt%
\def\figurepunct#1{\gdef\@figurepunct{#1}}\figurepunct{}%
%%
\newcommand\figmax[1]{\setbox\tempbox\hbox{\figurecontentnumfont#1\@figurepunct}%
                      \global\figurecontwidth\wd\tempbox%
                      %\global\advance\figurecontwidth4pt
                     }%
%%
\def\figurenumberline#1{\hb@xt@\@tempdima{\hbox to \figurecontwidth{\hfill#1\@figurepunct}\hfill}}%
%%
%%
\newcommand\l@cases[2]{\def\@tocrmarg{3em}%%
   \overfullrule\z@%
   \let\numberline\figurenumberline%
         \setlength\@tempdima{\figurecontwidth}%
         \advance\@tempdima\enspacefigurecontentwidth%
         \begingroup%
         \baselineskip11pt
            \parindent\z@%
            \rightskip\@tocrmarg%
            \advance\rightskip by\z@\@plus2cm%
            \parfillskip-\@tocrmarg%
            \leavevmode%
            \advance\leftskip\@tempdima%
            \hskip-\leftskip%
            \noindent{\small#1}%
            \nobreak\leaders\hbox{$\m@th\mkern\@dotsep mu\hbox{.}\mkern\@dotsep mu$}\hfill\nobreak%
            {\hfil\small#2}\par%
            \penalty\@highpenalty%
         \endgroup%
         \vspace{3pt}
                 }%
\makeatother
\begin{document}


\chapter*{Table of Legislation}

\contentsline{cases}{Abortion Act 1967}{150}{}

\contentsline{cases}{Access to Justice Act 1999}{155}{}

\contentsline{cases}{Brussels EEC Convention on Jurisdiction and the Enforcement of Judgments
in Civil and Commercial Matters 1968 (European Jurisdiction Convention)}{160}{}

\contentsline{cases}{\protect\numberline{2.4}Plot of the intensity of black-body radiation at a single frequency deep in the infrared
against temperature from a paper submitted to Annalen der Physik in February 1901
by Heinrich Rubens and Ferdinand Kurlbaum (1901). The figure clearly shows that
for long wavelengths the intensity varies linearly with the temperature, in agreement
with both the Planck law and the Rayleigh-Jeans law (which fails for shorter wave-
lengths). The data, however, are in sharp disagreement with the Wien law (Gearhart
2002, p. 180; Stone 2013, p. 9).}{5.87–5.88, 6.67,
7.111, 8.109, 9.61, 11.87, 14.96,
15.95, 17.104, 19.124, 21.75,
22.78, 23.231–23.232, 23.236,
23.238, 23.252, 24.45}{}


\end{document}
1

Here is a "proof of concept". I leave it to you to integrate it in the TOC. Basically, I typeset the text raggedright, and give preference to a short last line, so that it may leave enough space for the leaders and the first part of the line numbers (but no guarantee). I then unbox the last line of that paragraph, remove the filling space at the right, and then build a new paragraph with this line, the leaders, and the line numbers, set raggedleft with a left margin of about 0.3\linewidth. You can play with the number, of course. It uses quite a lot of low-level TeX trickery, some of which could be translated to official LaTeX code (for example using \setlength). It is also easily broken, giving wrong spacing etc. if you are not careful. It also works with \twocolumn, by the way.

enter image description here

\documentclass{book}

\newcommand\leftrightparagraph[2]{%
  \begingroup\vskip0pt
  \parskip=0pt\parindent=0pt
  % \box0 and \box2 are scratch box registers
  \setbox2=\vbox{\rightskip=0pt plus 2em
    \parfillskip=0.5\linewidth plus 0.2\linewidth minus 0.2\linewidth
    \strut#1\strut\par}%
  \unvbox2\setbox0=\lastbox
  \noindent\hbox{\strut\unhbox0\unskip\unskip}% remove \parfillskip and \rightskip
  \rightskip=0pt \leftskip=0pt plus 0.2\linewidth\parfillskip=0pt
  \hangafter 1 \hangindent 0.3\linewidth
  \leaders\hbox{\hbox{. }}\hfill
  #2\par\endgroup
}

\begin{document}

\chapter*{Table of Legislation}

\leftrightparagraph{Abortion Act 1967}{150}
\leftrightparagraph{Access to Justice Act 1999}{155}
\leftrightparagraph{Brussels EEC Convention on Jurisdiction and the Enforcement of Judgments
in Civil and Commercial Matters 1968 (European Jurisdiction Convention)}{160}
\leftrightparagraph{Plot of the intensity of black-body radiation at a single frequency deep in the infrared
against temperature from a paper submitted to Annalen der Physik in February 1901
by Heinrich Rubens and Ferdinand Kurlbaum (1901). The figure clearly shows that
for long wavelengths the intensity varies linearly with the temperature, in agreement
with both the Planck law and the Rayleigh-Jeans law (which fails for shorter wave-
lengths). The data, however, are in sharp disagreement with the Wien law (Gearhart
2002, p.~180; Stone 2013, p.~9).}{5.87–5.88, 6.67,
7.111, 8.109, 9.61, 11.87, 14.96,
15.95, 17.104, 19.124, 21.75,
22.78, 23.231–23.232, 23.236,
23.238, 23.252, 24.45}

\end{document}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.