In the list of tables and figures, how to set the same right margin for all lines of all the items?
As an example, the following MWE:
\documentclass{article}
\newlength{\largNum}
\newlength{\tocRightMargin}
\setlength{\tocRightMargin}{2cm}
\newlength{\tocLeftMarginSecondLineFigure}
\setlength{\tocLeftMarginSecondLineFigure}{6.5em}
\makeatletter
\renewcommand*\l@figure[2]{%
\settowidth{\largNum}{\hss #2}
\ifnum \c@tocdepth >\m@ne%
\addpenalty{-\@highpenalty}%
\vskip 1.0em \@plus\p@%
\setlength\@tempdima{3.4em}%
\noindent%
\begingroup
\pretolerance=10000
\parindent \z@ \rightskip \tocRightMargin%
\parfillskip -\tocRightMargin%
\leavevmode \normalsize%
\advance\leftskip \tocLeftMarginSecondLineFigure%
\hskip -\leftskip%
{\figurename\mbox{\hspace{4pt}}#1}\nobreak%
\leaders\hbox{$\m@th%
\mkern \@dotsep mu\hbox{.}\mkern \@dotsep%
mu$} \hfil\nobreak\hb@xt@%
\largNum{\hss #2}\par%
\penalty\@highpenalty%
\endgroup
\fi}
\makeatother
\begin{document}
\listoffigures
\begin{figure}
\caption{Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque justo justo, porta sagittis feugiat eget}
\end{figure}
\end{document}
Produces:
But I would like to have:
Best Answer
You want to do
rather than
\hfil
. Here's the code, where I made also a few other changes; for example the “Figure n” is typeset in a box with the right width.