为不同元素添加标题

为不同元素添加标题

我需要 2 个不同的图形标题:示例和图形。如果我使用\renewcommand,则每次出现图形时,计数器都不会停止并继续添加,例如:示例 1。图 2。示例 3。图 4...

我需要:示例 1。图 1。示例 2。图 2。

另外,是否可以将这两个列表分开ToC

谢谢。

答案1

这个包float也许能满足你的需要。

\usepackage{float}
\floatstyle{ruled} % Defines how the new floats should look like.
\newfloat{example}{htbp}{loe} % Defines a new float environment, with captions written to a file with extension `loe` (list of examples).
\floatname{example}{Example} % Label for captions
...
\begin{document}
...
\begin{example}
  \centering
  This is an example.
  \caption{Some example}\label{ex:a}
\end{example}
...
See example~\ref{ex:a}.
...
\listof{example}{List of Examples} % Print a list of captions of all examples.

要让图表(和表格)列表出现在目录中,您可以添加

% Add list of figures and tables to table of contents
\usepackage[nottoc]{tocbibind}

到序言部分。要将新浮点数列表(如示例列表)也添加到目录中,似乎我们必须修补软件包\listof提供的命令float。在 之后立即添加以下几行\usepackage{float}

\usepackage{xpatch}
% Add the lists of new floats to table of contents
\makeatletter
%\xpatchcmd\listof{\@starttoc}{\addcontentsline{toc}{section}{#2}\@starttoc}{}{}% For article class
\xpatchcmd\listof{\@starttoc}{\addcontentsline{toc}{chapter}{#2}\@starttoc}{}{}% For report and book class
\makeatother

这是一个完整的例子。

在此处输入图片描述

\documentclass{report}
\usepackage{graphicx}
 % Add list of figures and tables to table of contents
\usepackage[nottoc]{tocbibind}
\usepackage{float}
\usepackage{xpatch}
% Add the lists of new floats to table of contents
\makeatletter
%\xpatchcmd\listof{\@starttoc}{\addcontentsline{toc}{section}{#2}\@starttoc}{}{}% For article class
\xpatchcmd\listof{\@starttoc}{\addcontentsline{toc}{chapter}{#2}\@starttoc}{}{}% For report and book class
\makeatother
\floatstyle{ruled}
\newfloat{example}{htbp}{loe}
\floatname{example}{Example}
\begin{document}
\tableofcontents
\listoffigures
\listof{example}{List of Examples}
\chapter{The first chapter}
This document shows two figures, \ref{fig:a} and \ref{fig:b},
as well two examples, \ref{ex:a} and \ref{ex:b}.

\begin{figure}
  \centering
  \includegraphics[width=3cm]{example-image-a}
  \caption{Some figure}\label{fig:a}
\end{figure}
\begin{example}
  \centering
  This is an example for something.
  \caption{Some example}\label{ex:a}
\end{example}
\begin{figure}
  \centering
  \includegraphics[width=3cm]{example-image-b}
  \caption{Another figure}\label{fig:b}
\end{figure}
\begin{example}
  \centering
  Yet another example.
  \caption{Another example}\label{ex:b}
\end{example}
\end{document}

答案2

另一种方法是使用 package tocbasic,所有 KOMA 类都使用这种方法。
对于 KOMA 类,packagefloat不是最佳选择。

\documentclass{article}
\usepackage{graphicx}
\usepackage{tocbasic}
\DeclareNewTOC[
    type=example,
    types=examples,
    float,
name=Example]{loe}
\setuptoc{loe}{totoc}
\begin{document}

\tableofcontents


\rule{.8\textwidth}{.4pt}

This document shows two figures, \ref{fig:a} and \ref{fig:b},
as well two examples, \ref{ex:a} and \ref{ex:b}.

\begin{figure}
    \centering
    \includegraphics[width=3cm]{example-image-a}
    \caption{Some figure}\label{fig:a}
\end{figure}
\begin{example}
    \centering
    This is an example for something.
    \caption{Some example}\label{ex:a}
\end{example}
\begin{figure}
    \centering
    \includegraphics[width=3cm]{example-image-b}
    \caption{Another figure}\label{fig:b}
\end{figure}
\begin{example}
    \centering
    Yet another example.
    \caption{Another example}\label{ex:b}
\end{example}
\listoffigures
\listofexamples
\end{document}

相关内容