내 목록을 목차에 어떻게 추가하나요?

내 목록을 목차에 어떻게 추가하나요?

나는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}

편집 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새로운 부동 환경을 정의하고 이를 함께 사용하고 싶습니다 (환경 과 함께 부동을 lstlisting사용하는 것처럼 ).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}

관련 정보