# Conditional formatting for spaces in the List of Figures

I'm trying to format the spaces between figure labels according to the figure number space, so that figures in the LOF appear like the following:

1 XXXXX

100  XXXXX


1    XXXXX

100  XXXXX


However, using \if... \else doesn't seem to work:

\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}

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

\end{document}

• You could use \ifthenelse{\c@figure<99}{...}{...} with the ifthen package, to get rid of the error. But it seems that \l@figure is setted once for all entries. – dexteritas Aug 18 '17 at 12:54
• You don't want to use \c@figure (which is probably 0 at this point). You need to access the arguments then pass them on to \@docttedcline. – John Kormylo Aug 18 '17 at 15:01
• If you don't pass the arguments to \@dottedcline, you might need to end with \expandafter\fi} – John Kormylo Aug 18 '17 at 15:49

This was slightly complicated by the fact that the figure number was an argument of \numberline, not \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}%
\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}