![如何使用包 etoc 生成示例目录?](https://linux22.com/image/472367/%E5%A6%82%E4%BD%95%E4%BD%BF%E7%94%A8%E5%8C%85%20etoc%20%E7%94%9F%E6%88%90%E7%A4%BA%E4%BE%8B%E7%9B%AE%E5%BD%95%EF%BC%9F.png)
使用包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}