Search code examples
latexpdflatexxelatex

Removing spaces between chapter LoF in table of contents


I'm trying to remove the space in LoF between different chapters. i have tried different solutions(patching it as well) but it is not working. I have attached the codes below for your reference. Any help or pointers to resolve it would be highly appreciated.

Edit: Link to a minimal working project file depicting the error.

Working Example

\documentclass[twoside, 12pt]{report}
\usepackage[utf8]{inputenc}
\usepackage{pdfpages}

%package for higlighting text
\usepackage{color,soul}

%packages for multicol glossary, bibliography and list
\usepackage[section,numberedsection=autolabel, acronym]{glossaries}
\usepackage{setspace}
\usepackage{enumitem}
\usepackage[style=ieee]{biblatex}
\usepackage{glossary-mcols}
\usepackage{multicol}

%package for comments
\usepackage{verbatim}

%%Random text
\usepackage{lipsum}  

%packages for fancy headers
\usepackage{blindtext}
\usepackage{fancyhdr}
\usepackage{tikz}

%package for subfigures
\usepackage{subfigure}

\makeglossaries


% Use package below to change margins and graphics
\usepackage{graphicx}
\usepackage[a4paper,top=25mm,bottom=25mm,left=25mm,right=25mm]{geometry}

% text color package
\usepackage{xcolor}

% use to customize chapter headings of toc lof lot
\usepackage{tocloft}
\renewcommand{\cfttoctitlefont}{\hspace*{\fill}\Large\bfseries}
\renewcommand{\cftaftertoctitle}{\hspace*{\fill}}
\renewcommand{\cftlottitlefont}{\hspace*{\fill}\Large\bfseries}
\renewcommand{\cftafterlottitle}{\hspace*{\fill}}
\renewcommand{\cftloftitlefont}{\hspace*{\fill}\Large\bfseries}
\renewcommand{\cftafterloftitle}{\hspace*{\fill}}


\usepackage{sectsty}
\chapternumberfont{\Large} 
\chaptertitlefont{\Large}


\usepackage{hyperref}

%for table
\usepackage{booktabs}

%maths Package
\usepackage{amsmath}

%minted package
\usepackage[]{minted}
\usepackage{fancyvrb} 


%for greek words
\usepackage[utf8]{inputenc}
\usepackage[greek,english]{babel}
\usepackage{lmodern}
\usemintedstyle{vs}
\setminted{bgcolor=myGray,
    breaklines,
    mathescape,
    linenos,
    numbersep=5pt,
    frame=single,
    numbersep=5pt,
    xleftmargin=0pt,
    breaksymbolleft=\raisebox{0.8ex}{
    \small\reflectbox{\carriagereturn}},
    breaksymbolindentleft=0pt,
    breaksymbolsepleft=0pt,
    breaksymbolindentright=0pt,
    breaksymbolsepright=0pt
}


%for code listing
\usepackage{xcolor}
\usepackage{listings}
\definecolor{myGray}{RGB}{245, 239, 239}
\definecolor{maroon}{RGB}{128,0,0}
\definecolor{forestGreen}{RGB}{1,68,33}
\lstdefinestyle{mystyle}{
    backgroundcolor=\color{myGray},
    commentstyle=\color{forestGreen},
    keywordstyle=\color{blue},
    numberstyle=\tiny\color{gray},
    stringstyle=\color{maroon},
    basicstyle=\ttfamily\small,
    breakatwhitespace=false,         
    breaklines=true,                 
    captionpos=b,                    
    keepspaces=true,                 
    numbers=left,                    
    numbersep=5pt,                  
    showspaces=false,                
    showstringspaces=false,
    showtabs=false,                  
    tabsize=2,
    frame=single
}

\lstset{style=mystyle}


%Patch to remove the space in LoF, LoT, LoC per chapter basis
\usepackage{etoolbox}% http://ctan.org/pkg/etoolbox
\makeatletter
\patchcmd{\@chapter}{\addtocontents{lof}{\protect\addvspace{10\p@}}}{}{}{}% LoF
\patchcmd{\@chapter}{\addtocontents{lot}{\protect\addvspace{10\p@}}}{}{}{}% LoT
\makeatother



%for custom caption
\usepackage{caption}

% document begins here
\begin{document}


%Footer and header fancy - chapter x. ChapterName format
\fancyhead{}
\fancyhead[RO,LE]{\leftmark}
\fancyfoot{}
\fancyfoot[CE,CO]{\thepage}

\newpage
\phantomsection
\tableofcontents
\addcontentsline{toc}{chapter}{Table of Contents}


\newpage
\listoftables
\phantomsection
\addcontentsline{toc}{chapter}{\listtablename}

\newpage
\listoffigures
\phantomsection
\addcontentsline{toc}{chapter}{\listfigurename}

\newpage
\renewcommand{\lstlistingname}{Code}
\renewcommand{\lstlistlistingname}{List of \lstlistingname s}
\lstlistoflistings
\phantomsection
\addcontentsline{toc}{chapter}{\lstlistlistingname}





%CHAPTERS BEGIN
\pagenumbering{arabic}
\newpage

\input{Chapters/Intro}

\input{Chapters/Results}


\newpage
%%APPENDIX BEGINS
\fancyhead{}
\fancyfoot{}

\end{document}

Image showing the output i'm getting

Please find below the code for respective

The below figures are part of sample Intro file.

\begin{figure}[h]
    \centering
    \includegraphics[scale=0.5]{<someImage>}
    \caption{Software Development Lifecycle}
    \label{fig:swCycle}
\end{figure}
\begin{figure}[h]
    \centering
    \includegraphics[scale=0.5]{<someImage>}
    \caption{Software Development Lifecycle2}
    \label{fig:swCycle2}
\end{figure}

Results File

\begin{figure}[h]
    \centering
    \includegraphics[scale=0.5]{<someImage>}
    \caption{Software Development Lifecycle3}
    \label{fig:swCycle3}
\end{figure}

Solution

  • You could remove the spaces between the list entries of different chapters if you make the patches before you load hyperref:

    \documentclass[twoside, 12pt]{report}
    
    % use to customize chapter headings of toc lof lot
    \usepackage{tocloft}
    \renewcommand{\cfttoctitlefont}{\hspace*{\fill}\Large\bfseries}
    \renewcommand{\cftaftertoctitle}{\hspace*{\fill}}
    \renewcommand{\cftlottitlefont}{\hspace*{\fill}\Large\bfseries}
    \renewcommand{\cftafterlottitle}{\hspace*{\fill}}
    \renewcommand{\cftloftitlefont}{\hspace*{\fill}\Large\bfseries}
    \renewcommand{\cftafterloftitle}{\hspace*{\fill}}
    
    \usepackage{etoolbox}
    \makeatletter
    \patchcmd{\@chapter}{\addtocontents{lof}{\protect\addvspace{10\p@}}}{}{}{}
    \patchcmd{\@chapter}{\addtocontents{lot}{\protect\addvspace{10\p@}}}{}{}{}
    \makeatother
    
    % load hyperref after these patches
    \usepackage{hyperref}
    
    
    
    \begin{document}
    
    \listoffigures
    
    \chapter{test}
    
    \begin{figure}[htbp]
    \caption{heading}
    \end{figure}
    
    \chapter{test}
    
    \begin{figure}[htbp]
    \caption{heading}
    \end{figure}
    
    \end{document}
    

    enter image description here