第零章和浮点编号

第零章和浮点编号

考虑以下测试包的文档newfloat

\documentclass[a4paper, 10pt]{book}
\usepackage{lipsum}
\usepackage{caption}
\usepackage{graphicx}
\usepackage{newfloat}
\usepackage{hyperref}

\DeclareFloatingEnvironment[
    within = chapter,
    fileext = dia,
    listname = {List of Diagrams},
    name = {Diagram},
    placement = p,
]{diagram}
\captionsetup[diagram]{
    labelfont={small,bf},
    textfont={small},
}

\begin{document}
\setcounter{chapter}{-1}
\chapter{This is a chapter}
\lipsum[1]
\begin{diagram}[!h]
\begin{center}
\textbf{\textsc{DIAGRAM}}
\end{center}
\caption{This is meant to be a diagram.}
\end{diagram}
\lipsum[1]
\chapter{This is a chapter}
\lipsum[1]
\begin{diagram}[!h]
\begin{center}
\textbf{\textsc{DIAGRAM}}
\end{center}
\caption{This is meant to be a diagram.}
\end{diagram}
\lipsum[1]
\chapter{This is a chapter}
\lipsum[1]
\begin{diagram}[!h]
\begin{center}
\textbf{\textsc{DIAGRAM}}
\end{center}
\caption{This is meant to be a diagram.}
\end{diagram}
\lipsum[1]
\end{document}

从章节1(图表1.12.1...) 开始,图表的编号是正确的。但是章节的图表的0编号Diagram 1不是Diagram 0.1

如何制作Diagram 0.1章节编号格式0

答案1

最简单的方法可能是手动重新定义计数器的行为,而不是使用 键来执行此within操作\DeclareFloatingEnvironment

\documentclass[a4paper, 10pt]{book}
\usepackage{lipsum}
\usepackage{caption}
\usepackage{graphicx}
\usepackage{newfloat}
\usepackage{hyperref}

\DeclareFloatingEnvironment[
    fileext = dia,
    listname = {List of Diagrams},
    name = {Diagram},
    placement = p,
]{diagram}
\captionsetup[diagram]{
    labelfont={small,bf},
    textfont={small},
}
\renewcommand{\thediagram}{\arabic{chapter}.\arabic{diagram}}

\begin{document}
\setcounter{chapter}{-1}
\chapter{This is a chapter}
\lipsum[1]
\begin{diagram}[!h]
\begin{center}
\textbf{DIAGRAM}
\end{center}
\caption{This is meant to be a diagram.}
\end{diagram}
\lipsum[1]
\chapter{This is a chapter}
\lipsum[1]
\begin{diagram}[!h]
\begin{center}
\textbf{DIAGRAM}
\end{center}
\caption{This is meant to be a diagram.}
\end{diagram}
\lipsum[1]
\chapter{This is a chapter}
\lipsum[1]
\begin{diagram}[!h]
\begin{center}
\textbf{DIAGRAM}
\end{center}
\caption{This is meant to be a diagram.}
\end{diagram}
\lipsum[1]
\end{document}

相关内容