在表格和图表列表中,如何为所有项目的所有行设置相同的右边距?
例如,以下 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}
生成:
但我想要的是:
答案1
你想做
\leaders\hbox{...}\hskip 1\tocRightMargin plus 1fil\nobreak
而不是\hfil
。这是代码,我还做了一些其他更改;例如,“图 n” 排版在具有正确宽度的框中。
\documentclass{article}
\newlength{\largNum}
\newlength{\tocRightMargin} % Marge droite
\setlength{\tocRightMargin}{2cm}
\newlength{\tocLeftMarginSecondLineFigure}
\setlength{\tocLeftMarginSecondLineFigure}{6.5em}
\makeatletter
\renewcommand*\l@figure[2]{%
\settowidth{\largNum}{#2}%
\ifnum \c@tocdepth >\m@ne
\addpenalty{-\@highpenalty}%
\vskip 1.0em \@plus\p@
\setlength\@tempdima{3.4em}%
\noindent
\begingroup
\def\numberline##1{\makebox[\tocLeftMarginSecondLineFigure][l]{\figurename\ ##1}}%
\pretolerance=10000
\parindent \z@ \rightskip \tocRightMargin
\parfillskip -\tocRightMargin
\leavevmode \normalsize
\advance\leftskip \tocLeftMarginSecondLineFigure
\hskip -\leftskip
#1\nobreak
\leaders\hbox{$\m@th
\mkern \@dotsep mu\hbox{.}\mkern \@dotsep
mu$}\hskip 1\tocRightMargin plus 1fil\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}