图表列表中空格的条件格式

图表列表中空格的条件格式

我正在尝试根据图形编号空间来格式化图形标签之间的空格,以便 LOF 中的图形如下所示:

1 XXXXX

100  XXXXX

代替:

1    XXXXX

100  XXXXX

但是,使用\if... \else似乎不起作用:

\documentclass{report}
\usepackage{graphicx}

\makeatletter
\renewcommand*{\l@figure}{%
    \ifnum \c@figure< 99 \@dottedtocline{1}{1.5em}{4.5em}%
\else \@dottedtocline{1}{1.5em}{5.5em}%
\fi 
}
\makeatother

\begin{document}

\listoffigures

\begin{figure}
\centering
\rule{1cm}{1cm}
\caption{Figure}
\end{figure}

\addtocounter{figure}{99}

\begin{figure}
\centering
\rule{1cm}{1cm}
\caption{Figure}
\end{figure}

\end{document}

答案1

这稍微复杂一些,因为图形编号是的参数\numberline,而不是的\l@figure

\documentclass{report}
\usepackage{graphicx}

\newcommand{\tempfigure}{0}% reserve global name

\makeatletter
\renewcommand*{\l@figure}[2]% #1 = \numberline[number}{text}, #2 = page
{\bgroup
  \renewcommand{\numberline}[2]{\xdef\tempfigure{##1}}%
  {#1}% the rest is thrown away
\egroup
\ifnum \tempfigure< 99 \@dottedtocline{1}{1.5em}{4.5em}{#1}{#2}%
\else \@dottedtocline{1}{1.5em}{5.5em}{#1}{#2}%
\fi 
}
\makeatother

\begin{document}

\listoffigures

\begin{figure}
\centering
\rule{1cm}{1cm}
\caption{Figure}
\end{figure}

\addtocounter{figure}{99}

\begin{figure}
\centering
\rule{1cm}{1cm}
\caption{Figure}
\end{figure}

\end{document}

演示

相关内容