LaTeX forum ⇒ Text Formattinglstlistoflistings 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

Postby MakezHD » Fri Feb 15, 2019 1:08 pm

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: 197
Joined: Sun Nov 16, 2014 8:51 pm

Postby rais » Fri Feb 15, 2019 2:07 pm

I guess that depends on the class you're using.
For report class, you could try sth. like
  1. \usepackage{etoolbox}
  2. \makeatletter
  3. \patchcmd{\@chapter}{\chaptermark{#1}}{%
  4. \chaptermark{#1}%
  5. \addtocontents{lol}{\protect\addvspace{10\p@}}%
  6. }{\typeout{Chapters patched for list-of-listings.}}{\typeout{Could not patch chapters for list-of-listings.}}
  7. \makeatother

south of loading listings in your preamble.

KR
Rainer

MakezHD
Posts: 10
Joined: Thu Jan 21, 2016 8:19 pm

Postby MakezHD » Fri Feb 15, 2019 2:12 pm

rais wrote:I guess that depends on the class you're using.
For report class, you could try sth. like
  1. \usepackage{etoolbox}
  2. \makeatletter
  3. \patchcmd{\@chapter}{\chaptermark{#1}}{%
  4. \chaptermark{#1}%
  5. \addtocontents{lol}{\protect\addvspace{10\p@}}%
  6. }{\typeout{Chapters patched for list-of-listings.}}{\typeout{Could not patch chapters for list-of-listings.}}
  7. \makeatother

south of loading listings in your preamble.

KR
Rainer


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

rais
Posts: 197
Joined: Sun Nov 16, 2014 8:51 pm

Postby rais » Sun Feb 17, 2019 3:44 am

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

Postby MakezHD » Mon Feb 18, 2019 10:15 am

rais wrote:I guess that depends on the class you're using.
For report class, you could try sth. like
  1. \usepackage{etoolbox}
  2. \makeatletter
  3. \patchcmd{\@chapter}{\chaptermark{#1}}{%
  4. \chaptermark{#1}%
  5. \addtocontents{lol}{\protect\addvspace{10\p@}}%
  6. }{\typeout{Chapters patched for list-of-listings.}}{\typeout{Could not patch chapters for list-of-listings.}}
  7. \makeatother

south of loading listings in your preamble.

KR
Rainer


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

Image

rais
Posts: 197
Joined: Sun Nov 16, 2014 8:51 pm

Postby rais » Sat Feb 23, 2019 5:54 am

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
  1. \raggedbottom
to your preamble.
If that is not enough (you may now notice different space between headlines and first entries in LOF/LOT), add
  1. \renewcommand\lstlistoflistings{%
  2. \if@twocolumn
  3. \@restonecoltrue\onecolumn
  4. \else
  5. \@restonecolfalse
  6. \fi
  7. \chapter*{\lstlistlistingname}%
  8. \@mkboth{\MakeUppercase\lstlistlistingname}%
  9. {\MakeUppercase\lstlistlistingname}%
  10. \@starttoc{lol}%
  11. \if@restonecol\twocolumn\fi
  12. }
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

Postby MakezHD » Mon Feb 25, 2019 10:10 am

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
  1. \raggedbottom
to your preamble.
If that is not enough (you may now notice different space between headlines and first entries in LOF/LOT), add
  1. \renewcommand\lstlistoflistings{%
  2. \if@twocolumn
  3. \@restonecoltrue\onecolumn
  4. \else
  5. \@restonecolfalse
  6. \fi
  7. \chapter*{\lstlistlistingname}%
  8. \@mkboth{\MakeUppercase\lstlistlistingname}%
  9. {\MakeUppercase\lstlistlistingname}%
  10. \@starttoc{lol}%
  11. \if@restonecol\twocolumn\fi
  12. }
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!


Return to “Text Formatting”

Who is online

Users browsing this forum: No registered users and 6 guests