
Ich verwende diethesul
Klasse. 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.cls
Datei ändern.
Edit 1: Sorry, ich habe das tulhypref
Paket vergessen, daher sind bei dieser main.tex
Datei keine Lesezeichen vorhanden. Hier ist die richtige main.tex
Datei:
\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:
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}
Antwort1
Anstatt listings
den integrierten Mechanismus zu verwenden, würde ich lieber eine neue Floating-Umgebung definieren und diese zusammen mit Folgendem verwenden lstlisting
(genauso wie Sie ein table
Float zusammen mit einer tabular
Umgebung 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}