I have many images in a part of my document, now the list of figures numbers collide with its respective image caption as seen below. There would be enough space to move the text a bit more to the right… is there any way to reconfigure the LOF?
[Tex/LaTex] List of figures: numbers overlap image caption
spacingtable of contents
Related Solutions
A more elegant way to do this is to use the caption
package, which allows you to specify special formats for an individual figure. Here's an example:
\documentclass{article}
\usepackage{caption}
\usepackage[demo]{graphicx}
\DeclareCaptionLabelFormat{blank}{}
\begin{document}
\listoffigures
\begin{figure}[hpb]
\includegraphics[width=2cm,height=1cm]{foo}
\caption{A regular caption}
\end{figure}
\begin{figure}[hpb]
\includegraphics[width=2cm,height=2cm]{foo}
\captionsetup{textformat=empty,labelformat=blank}
\caption{A caption that doesn't appear under the figure}
\end{figure}
\begin{figure}[hpb]
\includegraphics[width=2cm,height=1cm]{foo}
\caption{The third figure}
\end{figure}
\end{document}
The additional part contents line (in the list of figures) is added at the begin of macro \figure
(\begin{figure}
). There the float has not yet started and the write directive for the part line goes at the place of the figure
in the source.
The float object will be created later in \@xfloat
. \caption
will then
write its contents line inside the float object. But the float object can
float to a location before the source code location, in your case with option t
. Then the two contents lines get out of order.
This can be fixed by moving the part contents line inside the float box.
Instead of the very begin of the float environment, still outside the float box, the following example hooks into \@floatboxreset
, which is automatically called at the begin of the float box. LaTeX remembers the type of the float object in \@captype
and macro \ext@<captype>
(<captype>
∈ {figure
, table
, ...}) contains the list type (\ext@figure
-> lof
). This way, also the other float types are supported automatically, if they follow the LaTeX conventions. For example, new floats, defined by package float
will work.
A new float type only needs a new toggle and the toggle to be reset at the
start of a new part. This is done by macro \AddFloatToggle
in the example.
\documentclass{scrreprt}
\usepackage{etoolbox}
\makeatletter
% Initialize variables
\newcommand*{\ResetFloatToggles}{}% toggle reset list for \part
\newcommand*{\thisparttitle}{}
\newcommand*{\thispartnumber}{}
\newcommand*{\AddFloatToggle}[1]{%
\newtoggle{no#1s}%
\apptocmd{\ResetFloatToggles}{%
\global\toggletrue{no#1s}%
}{}{}%
}
% Set variables and reset float toggles at the start of \part
\apptocmd{\@part}{%
% Remember part title and part number
\gdef\thisparttitle{#1}%
\gdef\thispartnumber{\thepart}%
\ResetFloatToggles
}{}{}
% Emit \addcontentsline at the begin of the float box
\apptocmd{\@floatboxreset}{%
% Test, if toggle exists for this float type.
% Since there isn't an official command for testing
% toggle existence, the internal code for testing
% is used, see the definition of \newtoggle.
\ifcsdef{etb@tgl@no\@captype s}{%
\iftoggle{no\@captype s}{%
% \@captype is the type of float, e.g. "figure", "table", "program"
% \ext@... (\ext@figure, \ext@table, \ext@program)
% contains the type/extension for the list of the float type, e.g.
% "lof", "lot", "lop".
\addcontentsline{\csname ext@\@captype\endcsname}{part}{%
\protect\numberline{\thispartnumber} {\thisparttitle}%
}%
\global\togglefalse{no\@captype s}%
}{}%
}{%
% unsupported float type
\typeout{Warning: there is no toggle for float type \@captype!}%
}%
}{}{}
\makeatother
\usepackage{float}
\newfloat{program}{tbp}{lop}[chapter]
\AddFloatToggle{figure}
\AddFloatToggle{table}
\AddFloatToggle{program}
\begin{document}
\listoftables
\listoffigures
\listof{program}{List of Programs}
\part{Part 1}
\begin{table}\caption{Part 1 Tab}\end{table}
\begin{program}\caption{Part 1 Program}\end{program}
\part{Part 2}
\begin{table}\caption{Part 2 Tab}\end{table}
\begin{figure}\caption{Part 2 Fig}\end{figure}
\end{document}
Best Answer
From the linked question in the comments, I figured out the following:
Which produces: