目次にリストを追加するにはどうすればよいですか?

目次にリストを追加するにはどうすればよいですか?

私はthesulクラス。目次に自分のリストを追加したいと思います。

次のコマンドを使用してそれを実行する方法を見つけました\addcontentsline{toc}{spsection}{Listings}:

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

しかし、問題は、このコマンドの使用により、すでに追加されている対応する PDF ブックマークが 2 回追加されることです。

したがって、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}

編集2: 結果は次のとおりです: ここに画像の説明を入力してください

しかし、回避策を見つけました。

コマンドを使用する場合は\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組み込みのメカニズムを使用する代わりに、新しいフローティング環境を定義して、それを一緒に使用します (環境と一緒に floatlstlistingを使用するのと同じように)。tabletabular

以下はスムーズに実行され、期待どおりの結果が得られました。

\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}

関連情報