如何使用 etoc 套件產生範例的目錄?

如何使用 etoc 套件產生範例的目錄?

透過包,etoc我可以使用命令輕鬆生成章節列表\tableofcontents

\locallistoftables它還可以使用命令和命令來產生列表和圖形\locallistoffigures

\tableofcontents %   <-- line 41 in main.tex

\listoffigures %   <-- line 43 in main.tex

\listoftables % <-- line 49 in main.tex

但是如何產生書中所有範例的清單呢?

例如我有兩個例子main.tex,如何像指令一樣自動產生所有例子的清單\listoffigures

\newmdenv[        % <---- line 26 in main.tex, exambox environment with `mdframed` package
    style=kaoboxstyle,
    backgroundcolor=Gray!12!White,
    frametitlebackgroundcolor=Gray!12!White,
]{exambox}

%% ... omit

\begin{exambox}[frametitle=Example 1]  % <--- line 79 in main.tex
\blindtext[1]
\label{exampe1}
\end{exambox}

\begin{exambox}[frametitle=Example 2]
\blindtext[3]
\label{exampe2}
\end{exambox}

mwe 來到這裡:

\documentclass[10pt,a4paper]{book}

\usepackage{blindtext}

\RequirePackage{tikz}
\RequirePackage[framemethod=TikZ]{mdframed}
\mdfdefinestyle{kaoboxstyle}{
    skipabove=1.5\topskip,
    skipbelow=.5\topskip,
    rightmargin=0pt,
    leftmargin=0pt,
    innerrightmargin=7pt,
    innerleftmargin=7pt,
    topline=false,
    bottomline=false,
    rightline=false,
    leftline=false,
    frametitlerule=true,
    linecolor=black,
    fontcolor=black,
    frametitlealignment=\raggedright\noindent % 防止全局缩进时,标题缩进
}
\RequirePackage{etoc} % Required to insert local tables of contents


\newmdenv[
    style=kaoboxstyle,
    backgroundcolor=gray!12!white,
    frametitlebackgroundcolor=gray!12!white,
]{exambox}

\begin{document}

\begingroup % Local scope for the following commands


% Turn on compatibility mode for the etoc package
\etocstandarddisplaystyle % "toc display" as if etoc was not loaded
\etocstandardlines % "toc lines as if etoc was not loaded

\tableofcontents % Output the table of contents

\listoffigures % Output the list of figures

% Comment both of the following lines to have the LOF and the LOT on different pages
\let\cleardoublepage\bigskip
\let\clearpage\bigskip

\listoftables % Output the list of tables

\endgroup



\chapter{First Chapter}

\blindtext
\begin{figure}
    \centering
    \includegraphics{example-image}
    \caption{fig 1}
    \label{fig:enter1}
\end{figure}

\begin{figure}
    \centering
    \includegraphics{example-image}
    \caption{fig 2}
    \label{fig:enter2}
\end{figure}


\chapter{Second Chapter}

\blindtext[2]

{\color{red} exambox ref: \ref{exampe1}}

\begin{exambox}[frametitle=Example 1]
\blindtext[1]
\label{exampe1}
\end{exambox}

\begin{exambox}[frametitle=Example 2]
\blindtext[3]
\label{exampe2}
\end{exambox}

\begin{figure}
    \centering
    \includegraphics{example-image}
    \caption{fig 3}
    \label{fig:enter3}
\end{figure}

\chapter{Third Chapter}

\blindtext
\begin{table}[ht]
    \centering
    \begin{tabular}{c|c}
       a  & b  \\
       c  & d
    \end{tabular}
    \caption{table 1}
    \label{tab:table1}
\end{table}


\chapter{Second Chapter}

\blindtext

\blindtext
\begin{table}[ht]
    \centering
    \begin{tabular}{c|c}
       1  & 2 \\
       3  & 4
    \end{tabular}
    \caption{table 2}
    \label{tab:table2}
\end{table}


\end{document}

相關內容