## LaTeX forum ⇒ Text Formatting ⇒ lstlistoflistings toc vertical spacings

Information and discussion about LaTeX's general text formatting features (e.g. bold, italic, enumerations, ...)
MakezHD
Posts: 10
Joined: Thu Jan 21, 2016 8:19 pm

### lstlistoflistings toc vertical spacings

A need my lstlistoflistings in the table of contents to be grouped by chapters and to use the same vertical spacings that are used in figures and tables listings.

What do I need to do add/modify to get those spacings?

Thank you.

rais
Posts: 273
Joined: Sun Nov 16, 2014 8:51 pm
I guess that depends on the class you're using.
For report class, you could try sth. like
`\usepackage{etoolbox}\makeatletter  \patchcmd{\@chapter}{\chaptermark{#1}}{%    \chaptermark{#1}%    \addtocontents{lol}{\protect\addvspace{10\p@}}%    }{\typeout{Chapters patched for list-of-listings.}}{\typeout{Could not patch chapters for list-of-listings.}}\makeatother`

KR
Rainer

MakezHD
Posts: 10
Joined: Thu Jan 21, 2016 8:19 pm
rais wrote:I guess that depends on the class you're using.
For report class, you could try sth. like
`\usepackage{etoolbox}\makeatletter  \patchcmd{\@chapter}{\chaptermark{#1}}{%    \chaptermark{#1}%    \addtocontents{lol}{\protect\addvspace{10\p@}}%    }{\typeout{Chapters patched for list-of-listings.}}{\typeout{Could not patch chapters for list-of-listings.}}\makeatother`

KR
Rainer

I forgot to say it's a book. Sorry.

rais
Posts: 273
Joined: Sun Nov 16, 2014 8:51 pm
MakezHD wrote:I forgot to say it's a book.

if you mean the standard book class, it should work the same way.
If you're using another class that typesets books, you'll have to let us know which one.

KR
Rainer

MakezHD
Posts: 10
Joined: Thu Jan 21, 2016 8:19 pm
rais wrote:I guess that depends on the class you're using.
For report class, you could try sth. like
`\usepackage{etoolbox}\makeatletter  \patchcmd{\@chapter}{\chaptermark{#1}}{%    \chaptermark{#1}%    \addtocontents{lol}{\protect\addvspace{10\p@}}%    }{\typeout{Chapters patched for list-of-listings.}}{\typeout{Could not patch chapters for list-of-listings.}}\makeatother`

KR
Rainer

Chapters are being grouped fine now but vertical spaces are yet not identical to the ones in the figures and tables listings.

rais
Posts: 273
Joined: Sun Nov 16, 2014 8:51 pm
In a book, LaTeX tries to keep the last line consistent throughout the pages. To that end, it may add vertical space between paragraphs, list entries, ...
So with different numbers of entries in LOF/LOL, you get different such added space.
If you don't want that, add
`\raggedbottom`
If that is not enough (you may now notice different space between headlines and first entries in LOF/LOT), add
`\renewcommand\lstlistoflistings{%    \if@twocolumn      \@restonecoltrue\onecolumn    \else      \@restonecolfalse    \fi    \chapter*{\lstlistlistingname}%      \@mkboth{\MakeUppercase\lstlistlistingname}%              {\MakeUppercase\lstlistlistingname}%    \@starttoc{lol}%    \if@restonecol\twocolumn\fi  }`
to above \makeatletter..\makeatother block. This will redefine \lstlistoflistings to behave the same way as \listoffigures does in a book class, hence the vertical space between `Listings' and the first entry in LOL should now be the same as between `List of figures' and the first entry in LOF (if there's the same number of entries LOF/LOL or \raggedbottom is active).

KR
Rainer

MakezHD
Posts: 10
Joined: Thu Jan 21, 2016 8:19 pm
rais wrote:In a book, LaTeX tries to keep the last line consistent throughout the pages. To that end, it may add vertical space between paragraphs, list entries, ...
So with different numbers of entries in LOF/LOL, you get different such added space.
If you don't want that, add
`\raggedbottom`
If that is not enough (you may now notice different space between headlines and first entries in LOF/LOT), add
`\renewcommand\lstlistoflistings{%    \if@twocolumn      \@restonecoltrue\onecolumn    \else      \@restonecolfalse    \fi    \chapter*{\lstlistlistingname}%      \@mkboth{\MakeUppercase\lstlistlistingname}%              {\MakeUppercase\lstlistlistingname}%    \@starttoc{lol}%    \if@restonecol\twocolumn\fi  }`
to above \makeatletter..\makeatother block. This will redefine \lstlistoflistings to behave the same way as \listoffigures does in a book class, hence the vertical space between `Listings' and the first entry in LOL should now be the same as between `List of figures' and the first entry in LOF (if there's the same number of entries LOF/LOL or \raggedbottom is active).

KR
Rainer

Thank you so much!