书籍章节附录中的图片编号

书籍章节附录中的图片编号

因此,我在书中每章附录的图号方面遇到了这个问题。附录的编号简直乱七八糟。我尝试了几个命令来对附录进行不同的编号,但文档的其余部分就是乱七八糟。下面是一张说明和描述问题的图片,以及一个 MWE。

问题

在此处输入图片描述

附录图片编号只是数字。我希望第一章附录的图编号为:1.1A、1.2A 1.3A,然后第二章附录的图编号为:2.1A、2.2A。理想情况下,不会弄乱其余图的编号。

最小工作示例(我删除了序言,但我可以将其包括在内)

主文件:

    \documentclass[12pt,letterpaper, notitlepage]{report}
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    \usepackage{amssymb, amsfonts, amsthm}
    \usepackage{graphicx}
    \usepackage{amsmath}
    \usepackage[sectionbib]{chapterbib}
    \usepackage{har2nat}
    \usepackage{changepage}
    \usepackage{pdflscape}
    \usepackage{subcaption}
    \usepackage{setspace}
    \usepackage{geometry}
    \usepackage{titlesec}
    \usepackage{float}
    \usepackage{array}
    \usepackage{placeins}
    \usepackage{bbm}
    \usepackage{longtable}
    \usepackage{pbox}
    \usepackage[font=small,labelfont=bf,margin=\parindent,tableposition=top]{caption}
    \usepackage[normalem]{ulem}
    \usepackage{datetime}
    \usepackage{epsfig}
    \usepackage{epstopdf}
    \usepackage{bm}
    \usepackage{multirow}
    \usepackage{lscape}
    \usepackage{soul}
    \usepackage[toc, page]{appendix}
    \usepackage{url}
    \usepackage{booktabs}
    \usepackage{bibentry}
    \usepackage{etoolbox}

    \onehalfspacing
    \setcounter{MaxMatrixCols}{10}
    \setlength{\textwidth}{6.7in}
    \setlength{\oddsidemargin}{-0.15in}
    \setlength{\textheight}{8.1in}

    \pagestyle{plain}
    \setlength{\parskip}{.0in}
    \newcommand{\figref}[1]{Figure~\ref{#1}}
    \newcommand{\tabref}[1]{Table~\ref{#1}}
    \newcommand{\secref}[1]{Section~\ref{#1}}
    \newcommand{\eqnref}[1]{equation (\ref{#1})}
    \newcommand{\chapref}[1]{Chapter~\ref{#1}}

    \renewcommand{\thesection}{\Roman{section}}
    \titleformat{\section}[block]{\normalsize\bfseries\filcenter}{\thesection.}{1em}{}
    \titlespacing*{\section}{0pt}{11pt plus 2pt minus 2pt}{11pt plus 2pt minus 2pt}
    \renewcommand{\thesubsection}{\Alph{subsection}}
    \titleformat{\subsection}{\normalsize\itshape\filcenter}{\thesubsection.}{1em}{}
    \titlespacing*{\subsection}{0pt}{11pt plus 2pt minus 2pt}{11pt plus 2pt minus 2pt}

    \titleformat{\subsubsection}{\normalsize\itshape}{\thesubsubsection.}{1em}{}
    \titlespacing*{\subsubsection}{0pt}{11pt plus 2pt minus 2pt}{11pt plus 2pt minus 2pt}
    \newdateformat{monthyeardate}{%
    \monthname[\THEMONTH], \THEYEAR}
    \useunder{\uline}{\ul}{}
    \def\code#1{\texttt{#1}}
    \newcommand\cites[1]{\citeauthor{#1}'s\ (\citeyear{#1})}
    \AtBeginEnvironment{appendices}{\renewcommand\thefigure{\arabic{chapter}.\arabic{figure}A}}


\begin{document}

\listoffigures

\include{TextPaper1}
\include{figures_Paper1}
\include{Paper1_Appendix}
\pagebreak
\FloatBarrier
\clearpage

\include{TextPaper2}
\include{figures_Paper2}
\pagebreak
\FloatBarrier
\clearpage

\end{document} 

第一章文件:

\chapter{Chapter 1}

Hello World

\begin{figure}[!htb]
\centering
\caption{Figure 1 Main text}
\makebox[\textwidth][c]{\includegraphics[width=1.0\textwidth]{test-figure.png}}
\end{figure}

\begin{figure}[!htb]
\centering
\caption{Figure 2 Main Text}
\makebox[\textwidth][c]{\includegraphics[width=0.7\textwidth]{test-figure.png}}
\end{figure}


\begin{appendices}


\pagebreak
\FloatBarrier
\begin{figure}[!htbp]
\centering
\caption{Figure 1 Appendix}
\makebox[\textwidth][c]{\includegraphics[width=1.0\textwidth]{test-figure.png}}
\end{figure}


\end{appendices} 

第二章 文件

\chapter{Chapter 2}

Hello World 2 

\begin{figure}[!htb]
\centering
\caption{Figure 3 Main text}
\makebox[\textwidth][c]{\includegraphics[width=1.0\textwidth]{test-figure.png}}
\end{figure}

下面是一个测试图:

在此处输入图片描述

答案1

下面的代码实现了您想要的图形编号。

此代码有两个重要部分。首先,我添加了一个钩子,用于etoolbox更改图号。其次,我\chapter{..}在后面包含一个命令\begin{appendices}。第二步为附录生成一个章节样式标题,并保存章节计数器的最后一个值,这样您就不会得到章节号为 0 的结果。

在此处输入图片描述

\documentclass{book}
\usepackage{appendix}
\usepackage{etoolbox}  % <=== add this

\AtBeginEnvironment{appendices}{\renewcommand\thefigure{\arabic{chapter}.\arabic{figure}A}}  % <=== add this

\begin{document}
\listoffigures

\chapter{Introduction}
Here we have figures \ref{fig:1} and \ref{fig:2}.

\begin{figure}
\caption{First Figure}\label{fig:1}
\end{figure}
\begin{figure}
\caption{Second Figure}\label{fig:2}
\end{figure}

\begin{appendices}

\chapter{Appendix to Chapter 1} %<=== add this to get title and non-zero chapter counter
Here we have appendix figures \ref{fig:a1} and \ref{fig:a2}.

\begin{figure}
\caption{First Appendix First Figure}\label{fig:a1}
\end{figure}
\begin{figure}
\caption{Second Appendix Second Figure}\label{fig:a2}
\end{figure}

\end{appendices}


\chapter{Conclusion}
\begin{figure}
\caption{Second Chapter Figure}\label{fig:3}
\end{figure}

\begin{appendices}

\chapter{Appendix to Chapter 2}
Here we have appendix figures \ref{fig:a3} and \ref{fig:a4}.

\begin{figure}
\caption{Second Appendix Second Figure}\label{fig:a3}
\end{figure}
\begin{figure}
\caption{Second Appendix Second Figure}\label{fig:a4}
\end{figure}

\end{appendices}

\end{document}  

如果您不希望\chapter{..}在附录中包含该命令,以下挂钩仍会将章节号放入图号中:

\makeatletter
\AtBeginEnvironment{appendices}{%
   \setcounter{figure}{0}%
   \renewcommand\thefigure{\arabic{@ppsavesec}.\arabic{figure}A}%
}

\makeatother

这将重置图形计数器以在附录中重新启动,并使用环境appendices保存了章节号的计数器。如果我将其放入先前的代码中并\chapter{..}从附录中删除命令,则结果是: 在此处输入图片描述

正如 David 所指出的,这些include命令不会影响此编号。如果我将这些编辑放入您发布的多文件代码中,则图编号是相同的。因此,使用第二个版本(在后面添加@ppsavesec且没有添加),我从您的文件中获得了以下内容: \chapter{..}\begin{appendices}在此处输入图片描述

相关内容