[Tex/LaTex] Remove spacing between per-chapter figures in LoF

spacingtable of contents

When I'm generating a List of Figures in my project, all figures are grouped by chapter. I would like to have the whole list without any additional new lines between different chapters.

How it looks like:

Figure 1.1 
Figure 1.2

Figure 2.1

Figure 3.1 
Figure 3.2

How it should:

Figure 1.1 
Figure 1.2
Figure 2.1
Figure 3.1 
Figure 3.2

I tried to apply the following solutions but failed completely :

My main file:

\documentclass[12pt,oneside,titlepage,utf8x]{report}

\usepackage{times,a4wide,multirow,tabularx,graphicx} 
\usepackage{psfrag,fancyhdr,longtable}

\usepackage[T1]{fontenc}
\usepackage{float}
\usepackage[utf8]{inputenc}

\usepackage{url}
\usepackage{color}
\usepackage{verbatim}
\usepackage{fancyvrb}
\usepackage{natbib}
\usepackage{relsize}

\usepackage{caption}
\captionsetup[longtable]{belowskip=10pt}

\usepackage[left=4cm,top=2cm,right=3cm,bottom=2.5cm]{geometry}

\renewcommand{\chaptermark}[1]{\markboth{\nouppercase{\thechapter.\ #1}}{}}
\pagestyle{fancy}
\headheight 30pt
\rhead{}
\lfoot{}
\cfoot{\thepage}
\rfoot{}

\setlength{\parindent}{2em}
\setlength{\parskip}{1em}
\linespread{1.3} 

\begin{document}

\begin{titlepage}
\maketitle
\end{titlepage}

\tableofcontents

\chapter{First}
\label{sec:First}
\input{chapter1/chapter1}

\chapter{Second}
\label{sec:Second}
\input{chapter2/chapter2}

\chapter{Third}
\label{sec:Third}
\input{chapter3/chapter3}

\relsize{-1}
\listoffigures
\normalsize

\bibliography{praca_mgr}
\bibliographystyle{plain}
\nocite{*}

\end{document}

Best Answer

This is done automatically when you call \chapter, as can be seen from its definition in book.cls and report.cls:

\newcommand\chapter{\if@openright\cleardoublepage\else\clearpage\fi
                    \thispagestyle{plain}%
                    \global\@topnum\z@
                    \@afterindentfalse
                    \secdef\@chapter\@schapter}
\def\@chapter[#1]#2{\ifnum \c@secnumdepth >\m@ne
                       \if@mainmatter
                         \refstepcounter{chapter}%
                         \typeout{\@chapapp\space\thechapter.}%
                         \addcontentsline{toc}{chapter}%
                                   {\protect\numberline{\thechapter}#1}%
                       \else
                         \addcontentsline{toc}{chapter}{#1}%
                       \fi
                    \else
                      \addcontentsline{toc}{chapter}{#1}%
                    \fi
                    \chaptermark{#1}%
                    \addtocontents{lof}{\protect\addvspace{10\p@}}% <-- Gap in LoF
                    \addtocontents{lot}{\protect\addvspace{10\p@}}% <-- Gap in LoT
                    \if@twocolumn
                      \@topnewpage[\@makechapterhead{#2}]%
                    \else
                      \@makechapterhead{#2}%
                      \@afterheading
                    \fi}

Add the following to your document preamble:

\usepackage{etoolbox}% http://ctan.org/pkg/etoolbox
\makeatletter
% \patchcmd{<cmd>}{<search>}{<replace>}{<succes>}{<failure>}
\patchcmd{\@chapter}{\addtocontents{lof}{\protect\addvspace{10\p@}}}{}{}{}% LoF
\patchcmd{\@chapter}{\addtocontents{lot}{\protect\addvspace{10\p@}}}{}{}{}% LoT
\makeatother

The above patch removes the insertion of \addvspace to both the LoF and the LoT; the cause of the additional gap between entries on a per-chapter basis.

enter image description here

\documentclass{report}
\newcommand{\insertfigure}{\begin{figure}\caption{A figure}\end{figure}}
\usepackage{etoolbox}% http://ctan.org/pkg/etoolbox
\makeatletter
% \patchcmd{<cmd>}{<search>}{<replace>}{<succes>}{<failure>}
\patchcmd{\@chapter}{\addtocontents{lof}{\protect\addvspace{10\p@}}}{}{}{}
\patchcmd{\@chapter}{\addtocontents{lot}{\protect\addvspace{10\p@}}}{}{}{}
\makeatother
\begin{document}
\tableofcontents
\listoffigures
\chapter{A chapter}\insertfigure\insertfigure\insertfigure
\chapter{A chapter}\insertfigure\insertfigure\insertfigure
\chapter{A chapter}\insertfigure\insertfigure\insertfigure
\chapter{A chapter}\insertfigure\insertfigure\insertfigure
\end{document}

You can choose to use either both or only one by commenting out the required patch. An easier patch to remove both gap insertions would be

\usepackage{etoolbox}% http://ctan.org/pkg/etoolbox
\makeatletter
\def\@gobblesix#1#2#3#4#5#6{}
\patchcmd{\@chapter}% <cmd>
  {\chaptermark{#1}}% <search>
  {\chaptermark{#1}\@gobblesix}% <replace>
  {}{}% <success><failure>
\makeatother
Related Question