I'm writing my thesis and I have certain code-snippets to show. I'm using the the listings
package embedded in a custom float
environment to display them.
To list them in an index at the beginning of my document - similar to \listoffigures
- I use:
\listof{code}{List of Code}
This (technically) works as desired but looks completely different to my list of figures. See screenshot below (List of Figures on the left, List of Code on the right).
Why, and how to fix this? Or how to modify the \listof{}{}
layout to look similar to the one of \listoffigures
?
I tried this workaround which redefines the layout but it's not working as desired (still looks different) and is throwing more errors than I could post here.
Update 1: After some hours of trying to figure out of what wrong with my document (It's really bloated already.) I'll try to explain this with a minimal working example. Notice the screenshots below.
\documentclass[12pt,a4paper,twoside,openright]{report}
\usepackage[english]{babel}
\usepackage{float}
\newfloat{algo}{tbp}{loa}[chapter]
\setlength{\parskip}{3mm} % !
\setlength{\parindent}{3mm} % !
\frenchspacing
\sloppy
\begin{document}
\listoffigures
\listof{algo}{List of Algorithms}
\chapter{foo}
\begin{figure}
\centering
\rule{1cm}{1cm}
\caption{A figure}
\end{figure}
\begin{algo}
(algo)
\caption{An algorithm}
\end{algo}
\begin{figure}
\centering
\rule{1cm}{1cm}
\caption{Another figure}
\end{figure}
\begin{algo}
(algo)
\caption{Another algorithm}
\end{algo}
\chapter{bar}
\begin{figure}
\centering
\rule{1cm}{1cm}
\caption{Yet another figure}
\end{figure}
\begin{algo}
(algo)
\caption{Yet another algorithm}
\end{algo}
\end{document}
Parskip and parindent seem to play an important role, still I dont get a result as mentioned in lockstep's answer (with the spacing between chapters) ...
Update 2: Okay, now I found the reason why it's not working. It's the hyperref
package. Updated MWE:
\documentclass[12pt,a4paper,twoside,openright]{report}
\usepackage[english]{babel}
\usepackage{float}
\newfloat{algo}{tbp}{loa}[chapter]
% \setlength{\parskip}{3mm}
% \setlength{\parindent}{3mm}
\frenchspacing
\sloppy
% \usepackage{hyperref} % !!!
% \hypersetup{pdftitle={Bachelorthesis}} % !!!
% \hypersetup{colorlinks=false} % !!!
% \hypersetup{plainpages=false} % !!!
% \hypersetup{pdfborder={0 0 0}} % !!!
\usepackage{etoolbox}
\makeatletter
\patchcmd{\@chapter}%
{\addtocontents{lof}}%
{\addtocontents{loa}{\protect\addvspace{10pt}}%
\addtocontents{lof}}%
{\typeout{*** SUCCESS ***}}{\typeout{*** FAIL ***}}
\makeatother
\begin{document}
\listoffigures
\listof{algo}{List of Algorithms}
\chapter{foo}
\begin{figure}
\centering
\rule{1cm}{1cm}
\caption{A figure}
\end{figure}
\begin{algo}
(algo)
\caption{An algorithm}
\end{algo}
\begin{figure}
\centering
\rule{1cm}{1cm}
\caption{Another figure}
\end{figure}
\begin{algo}
(algo)
\caption{Another algorithm}
\end{algo}
\chapter{bar}
\begin{figure}
\centering
\rule{1cm}{1cm}
\caption{Yet another figure}
\end{figure}
\begin{algo}
(algo)
\caption{Yet another algorithm}
\end{algo}
\end{document}
Uncommenting the hyperref package and settings messed up the layout of the custom \listof
.
So to break down this issue:
- How to adjust
\parskip
and\parindent
without messing up the lists? - How to avoid
hyperref
package messing around with the layout?
Update 3: Closed this question:
- How to adjust
\parskip
and\parindent
without messing up the lists? I asked a follow-up question here: How to avoid\parskip
being applied to\listoffigures
etc.? - How to avoid
hyperref
package messing around with the layout? Solved: Simply loading hyperref at the end of all packages and after\makeatother
.
Thanks to Frank Mittelbach's workaround which helped me to solve the layout issue till this point.
\documentclass[12pt,a4paper,twoside,openright]{report}
, added MWE now.