
我正在使用thesul
班級。我想將我的清單添加到目錄中。
我找到了一種使用命令來做到這一點的方法\addcontentsline{toc}{spsection}{Listings}
:
\tableofcontents
\listoffigures
\listoftables
\lstlistoflistings
\addcontentsline{toc}{spsection}{Listings}
但問題是,由於使用了該命令,已經添加的相應PDF書籤被再次添加。
所以,也許我需要修改該thesul.cls
文件。
編輯1:抱歉,我忘記了tulhypref
包包,所以這個文件沒有書籤main.tex
。這是正確的main.tex
文件:
\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}
但我找到了一個解決方法。
當我使用該\lstlistoflistings
命令時,我需要執行以下操作:
\hypersetup{bookmarksdepth=-1}
\lstlistoflistings
\hypersetup{bookmarksdepth}
這是完整的程式碼:
\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}
答案1
listings
我不想使用內建機制,而是定義一個新的浮動環境並將其與以下內容一起使用lstlisting
(就像將table
浮動與tabular
環境一起使用一樣):
以下運行順利並給出了預期結果:
\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}