0

I need to put \listoffigures, \listoftables and \lstlistoflistings on the same page. The first two are ok, but the list of listings ends on a different page. This is what I tried:

\begingroup
\let\clearpage\relax
\listoffigures
\listoftables
\lstlistoflistings
\endgroup

But the output is this:

wrong space between lists.

Also, the list of listings (Elenco dei listati di codice in the image) is on page vii, but with this commands it appears on page v in the table of contents:

\tableofcontents
\cleardoublepage
\addcontentsline{toc}{chapter}{\listfigurename}
\cleardoublepage
\addcontentsline{toc}{chapter}{\listtablename}
\cleardoublepage
\addcontentsline{toc}{chapter}{\lstlistlistingname}

wrong table of contents

How do I fix that?

EDIT:
minimum working example, I hope this is how a MWE is meant to be as it is the first time I use Latex. Sorry I had to repeat the same image and table many times, but the problem occur only if list of images and list of tables are more than one page. I also included all the packages I use, in case there are some compatibility issues that I don't know.

\documentclass[a4paper,12pt]{book}
\usepackage[utf8]{inputenc}
\usepackage[italian]{babel}
\usepackage{fancyhdr}
\usepackage{sectsty}
\usepackage[left=3cm, right=3cm, bottom=3cm]{geometry}
\usepackage{setspace}
\usepackage{verbatim}
\usepackage{listings}
\usepackage[hang,small,sf,font=scriptsize, labelfont=bf]{caption}
\usepackage{subcaption}
\usepackage{graphicx}
\usepackage[stable]{footmisc}
\usepackage{cite}
\usepackage[english]{varioref}
\usepackage[usenames]{color}
\usepackage{xcolor}
\usepackage{colortbl}
\usepackage[hidelinks]{hyperref}
\usepackage{url}
\usepackage{amsmath}
\usepackage{mathrsfs}
\usepackage{algorithm}
\usepackage{algpseudocode}
\usepackage{csquotes}
\usepackage{lipsum}
\usepackage{mdframed}
\usepackage{tcolorbox}
\tcbuselibrary{breakable}
\usepackage[toc,page]{appendix}

\begin{document}

\thispagestyle{empty} \cleardoublepage

\pagenumbering{roman} \thispagestyle{empty}

\clearpage{\pagestyle{plain}\cleardoublepage} \tableofcontents \cleardoublepage \addcontentsline{toc}{chapter}{\listfigurename} \cleardoublepage \addcontentsline{toc}{chapter}{\listtablename} \cleardoublepage \addcontentsline{toc}{chapter}{\lstlistlistingname}

\begingroup \let\clearpage\relax \listoffigures \listoftables \lstlistoflistings \endgroup

\clearpage{\pagestyle{plain}\cleardoublepage} \pagenumbering{arabic}

\clearpage{\pagestyle{plain}\cleardoublepage} \chapter{Test} \label{chapter:test} \begin{figure} \centering \includegraphics[width=0.3\textwidth]{frog.jpg} \caption{\label{fig:frog}This frog was uploaded via the file-tree menu.} \end{figure} \begin{figure} \centering \includegraphics[width=0.3\textwidth]{frog.jpg} \caption{\label{fig:frog}This frog was uploaded via the file-tree menu.} \end{figure}\begin{figure} \centering \includegraphics[width=0.3\textwidth]{frog.jpg} \caption{\label{fig:frog}This frog was uploaded via the file-tree menu.} \end{figure} \begin{figure} \centering \includegraphics[width=0.3\textwidth]{frog.jpg} \caption{\label{fig:frog}This frog was uploaded via the file-tree menu.} \end{figure} \begin{figure} \centering \includegraphics[width=0.3\textwidth]{frog.jpg} \caption{\label{fig:frog}This frog was uploaded via the file-tree menu.} \end{figure} \begin{figure} \centering \includegraphics[width=0.3\textwidth]{frog.jpg} \caption{\label{fig:frog}This frog was uploaded via the file-tree menu.} \end{figure} \begin{figure} \centering \includegraphics[width=0.3\textwidth]{frog.jpg} \caption{\label{fig:frog}This frog was uploaded via the file-tree menu.} \end{figure} \begin{figure} \centering \includegraphics[width=0.3\textwidth]{frog.jpg} \caption{\label{fig:frog}This frog was uploaded via the file-tree menu.} \end{figure} \begin{figure} \centering \includegraphics[width=0.3\textwidth]{frog.jpg} \caption{\label{fig:frog}This frog was uploaded via the file-tree menu.} \end{figure} \begin{figure} \centering \includegraphics[width=0.3\textwidth]{frog.jpg} \caption{\label{fig:frog}This frog was uploaded via the file-tree menu.} \end{figure} \begin{figure} \centering \includegraphics[width=0.3\textwidth]{frog.jpg} \caption{\label{fig:frog}This frog was uploaded via the file-tree menu.} \end{figure} \begin{figure} \centering \includegraphics[width=0.3\textwidth]{frog.jpg} \caption{\label{fig:frog}This frog was uploaded via the file-tree menu.} \end{figure} \begin{figure} \centering \includegraphics[width=0.3\textwidth]{frog.jpg} \caption{\label{fig:frog}This frog was uploaded via the file-tree menu.} \end{figure} \begin{figure} \centering \includegraphics[width=0.3\textwidth]{frog.jpg} \caption{\label{fig:frog}This frog was uploaded via the file-tree menu.} \end{figure} \begin{figure} \centering \includegraphics[width=0.3\textwidth]{frog.jpg} \caption{\label{fig:frog}This frog was uploaded via the file-tree menu.} \end{figure} \begin{table} \centering \begin{tabular}{l|r} Item & Quantity \\hline Widgets & 42 \ Gadgets & 13 \end{tabular} \caption{\label{tab:widgets}An example table.} \end{table} \begin{table} \centering \begin{tabular}{l|r} Item & Quantity \\hline Widgets & 42 \ Gadgets & 13 \end{tabular} \caption{\label{tab:widgets}An example table.} \end{table} \begin{table} \centering \begin{tabular}{l|r} Item & Quantity \\hline Widgets & 42 \ Gadgets & 13 \end{tabular} \caption{\label{tab:widgets}An example table.} \end{table} \begin{table} \centering \begin{tabular}{l|r} Item & Quantity \\hline Widgets & 42 \ Gadgets & 13 \end{tabular} \caption{\label{tab:widgets}An example table.} \end{table} \begin{table} \centering \begin{tabular}{l|r} Item & Quantity \\hline Widgets & 42 \ Gadgets & 13 \end{tabular} \caption{\label{tab:widgets}An example table.} \end{table} \begin{table} \centering \begin{tabular}{l|r} Item & Quantity \\hline Widgets & 42 \ Gadgets & 13 \end{tabular} \caption{\label{tab:widgets}An example table.} \end{table} \begin{table} \centering \begin{tabular}{l|r} Item & Quantity \\hline Widgets & 42 \ Gadgets & 13 \end{tabular} \caption{\label{tab:widgets}An example table.} \end{table} \begin{table} \centering \begin{tabular}{l|r} Item & Quantity \\hline Widgets & 42 \ Gadgets & 13 \end{tabular} \caption{\label{tab:widgets}An example table.} \end{table} \begin{table} \centering \begin{tabular}{l|r} Item & Quantity \\hline Widgets & 42 \ Gadgets & 13 \end{tabular} \caption{\label{tab:widgets}An example table.} \end{table} \begin{table} \centering \begin{tabular}{l|r} Item & Quantity \\hline Widgets & 42 \ Gadgets & 13 \end{tabular} \caption{\label{tab:widgets}An example table.} \end{table} \begin{table} \centering \begin{tabular}{l|r} Item & Quantity \\hline Widgets & 42 \ Gadgets & 13 \end{tabular} \caption{\label{tab:widgets}An example table.} \end{table} \begin{table} \centering \begin{tabular}{l|r} Item & Quantity \\hline Widgets & 42 \ Gadgets & 13 \end{tabular} \caption{\label{tab:widgets}An example table.} \end{table}\begin{table} \centering \begin{tabular}{l|r} Item & Quantity \\hline Widgets & 42 \ Gadgets & 13 \end{tabular} \caption{\label{tab:widgets}An example table.} \end{table} \begin{table} \centering \begin{tabular}{l|r} Item & Quantity \\hline Widgets & 42 \ Gadgets & 13 \end{tabular} \caption{\label{tab:widgets}An example table.} \end{table} \lstinputlisting[language=Python, caption=test, label=ls:rectF]{test.py} \lstinputlisting[language=Python, caption=test, label=ls:rectF]{test.py} \lstinputlisting[language=Python, caption=test, label=ls:rectF]{test.py} \lstinputlisting[language=Python, caption=test, label=ls:rectF]{test.py} \lstinputlisting[language=Python, caption=test, label=ls:rectF]{test.py} \lstinputlisting[language=Python, caption=test, label=ls:rectF]{test.py} \lstinputlisting[language=Python, caption=test, label=ls:rectF]{test.py} \lstinputlisting[language=Python, caption=test, label=ls:rectF]{test.py} \lstinputlisting[language=Python, caption=test, label=ls:rectF]{test.py} \lstinputlisting[language=Python, caption=test, label=ls:rectF]{test.py} \lstinputlisting[language=Python, caption=test, label=ls:rectF]{test.py}

\end{document}

As you can see, the list of tables starts immediately after the list of images, but the list of listings starts on new page...I want it to start immediately after the list of tables. In case you need it, I used this class for listings:

Class test():
    def __init__(self):
        pass
def func(self):
    pass

The frog image: frog

Deffo
  • 53
  • 1
    Hi and welcome? Could you put a complete MWE (minimal working example) in here, so we could run the code and reproduce your problem? – canIchangethis Nov 18 '22 at 12:25
  • @canIchangethis added it to the question...let me know if it is ok or you need more. And sorry I forgot to say Hi, I know I should have but I completely forgot it! – Deffo Nov 19 '22 at 10:59

1 Answers1

0

Welcome to Tex.

The reason for this is that you are using the book class. By default the book class opens new chapters on the right.

You can fix your problem by changing the first line of your MWE and adding the option openany, like so: \documentclass[a4paper,12pt,openany]{book}. However, this will also cause chapters to open on the right.

So for your case I would suggest to use following for listing your contents tables:

\begingroup
\let\clearpage\relax

\listoffigures \listoftables

\makeatletter
\@openrightfalse
\makeatother

    \lstlistoflistings

\makeatletter
\@openrighttrue
\makeatother

\endgroup

This code snippet will disable openright:

\makeatletter
    \@openrightfalse
\makeatother

This code snippet will enable openright again:

\makeatletter
    \@openrighttrue
\makeatother

I have learned this from this answer: https://tex.stackexchange.com/a/203721/140011

nhck
  • 740
  • Thank you! I also solved the problem of the wrong page numbering by moving each \addcontentsline before the corresponding section instead of grouping them all together, like this: \tableofcontents \cleardoublepage \begingroup \let\clearpage\rela \addcontentsline{toc}{chapter}{\listfigurename} \listoffigures \addcontentsline{toc}{chapter}{\listtablename} \listoftables \makeatletter \@openrightfalse \makeatother \addcontentsline{toc}{chapter}{\lstlistlistingname} \lstlistoflistings \makeatletter \@openrighttrue \makeatother \endgroup – Deffo Nov 22 '22 at 16:30