Wie füge ich meine Einträge zum Inhaltsverzeichnis hinzu?

Wie füge ich meine Einträge zum Inhaltsverzeichnis hinzu?

Ich verwende diethesulKlasse. Ich möchte meine Einträge zum Inhaltsverzeichnis hinzufügen.

Ich habe eine Möglichkeit gefunden, dies mit dem folgenden \addcontentsline{toc}{spsection}{Listings}Befehl zu tun:

\tableofcontents
\listoffigures
\listoftables
\lstlistoflistings
\addcontentsline{toc}{spsection}{Listings}

Das Problem besteht allerdings darin, dass das entsprechende, bereits hinzugefügte PDF-Lesezeichen durch die Verwendung dieses Befehls ein zweites Mal hinzugefügt wird.

Vielleicht muss ich die thesul.clsDatei ändern.


Edit 1: Sorry, ich habe das tulhyprefPaket vergessen, daher sind bei dieser main.texDatei keine Lesezeichen vorhanden. Hier ist die richtige main.texDatei:

\documentclass{thesul}
\usepackage{tulhypref} % for bookmarks
\usepackage{listings} % for \lstlistoflistings
\begin{document}
    \tableofcontents
    \listoffigures
    \listoftables
    \lstlistoflistings
    \addcontentsline{toc}{spsection}{Listings}
    \chapter{My first chapter}

    Hello, this is my first chapter.

    \section{My first section}

    Hello, this is my first section.

    \begin{lstlisting}
echo "hello world";
    \end{lstlisting}
\end{document}

Bearbeitung 2: Hier ist das Ergebnis: Bildbeschreibung hier eingeben

Aber ich habe einen Workaround gefunden.

Wenn ich den Befehl verwende \lstlistoflistings, muss ich Folgendes tun:

\hypersetup{bookmarksdepth=-1}
\lstlistoflistings
\hypersetup{bookmarksdepth}

Hier ist der vollständige Code:

\documentclass{thesul}
\usepackage{tulhypref} % for bookmarks
\usepackage{listings} % for \lstlistoflistings
\begin{document}
    \tableofcontents
    \listoffigures
    \listoftables
    \hypersetup{bookmarksdepth=-1} % add this line (to disable bookmarks)
    \lstlistoflistings
    \hypersetup{bookmarksdepth} % add this line (to enable bookmarks)
    \addcontentsline{toc}{spsection}{Listings}
    \chapter{My first chapter}

    Hello, this is my first chapter.

    \section{My first section}

    Hello, this is my first section.

    \begin{lstlisting}
echo "hello world";
    \end{lstlisting}
\end{document}

Hier ist das Ergebnis: Bildbeschreibung hier eingeben

Antwort1

Anstatt listingsden integrierten Mechanismus zu verwenden, würde ich lieber eine neue Floating-Umgebung definieren und diese zusammen mit Folgendem verwenden lstlisting(genauso wie Sie ein tableFloat zusammen mit einer tabularUmgebung verwenden):

Das Folgende läuft reibungslos und liefert die erwarteten Ergebnisse:

\documentclass{thesul}
\usepackage{tulhypref} % for bookmarks
\usepackage{listings} % for \lstlistoflistings

\usepackage{newfloat}
\DeclareFloatingEnvironment[
  fileext = lol ,
  listname = {List Of Listings} ,
  name = Listing
]{listing}

\begin{document}

\tableofcontents
\listoffigures
\listoftables
\listoflistings

\chapter{My first chapter}
Hello, this is my first chapter.

\section{My first section}
Hello, this is my first section.

\begin{listing}
  \begin{lstlisting}
echo "hello world";
  \end{lstlisting}
  \caption{My listing's caption.}
\end{listing}

\end{document}

verwandte Informationen