我正在使用subappendices
来自包的环境appendix
在每章末尾添加附录。我想要的是Appendix
根据附录部分的节数在目录中选择单数或复数形式。还需要在目录中添加图表。
下面显示的 MWE 始终在目录中显示“附录”,在内容中显示“附录”。
\documentclass[11pt, a4paper, twoside]{book}
\RequirePackage[title,titletoc]{appendix}
\usepackage{etoolbox}
\AtBeginEnvironment{subappendices}{%
\section*{Appendix}
\addcontentsline{toc}{section}{Appendices}
\counterwithin{figure}{section}
\counterwithin{table}{section}
}
\AtEndEnvironment{subappendices}{%
\counterwithout{figure}{section}
\counterwithin{figure}{chapter}
\counterwithout{table}{section}
\counterwithin{table}{chapter}
}
\begin{document}
\tableofcontents % always show "Appendices" in TOC and "Appendix" in the content
\listoffigures
\listoftables
\chapter{First chapter}
\section{A section}
\begin{subappendices}
\section{First appendix}
\begin{table}[h!]
\begin{center}
\caption{A simple table.}
\label{tab:table1}
\begin{tabular}{l|c|r}
Value 1 & Value 2 & Value 3\\
\hline
1 & 1110.1 & a\\
2 & 10.1 & b\\
\end{tabular}
\end{center}
\end{table}
\end{subappendices}
\chapter{Second chapter}
\section{A section}
\begin{subappendices}
\section{First appendix}
\section{Second appendix}
\end{subappendices}
\end{document}
的 MWE@Mico 的方法如下所示,其中图表列表和表格列表中缺少附录中的图表。
更新:很抱歉我犯了错误。附录中的图表和表格并没有从图表列表和表格列表中遗漏。它们使用连续编号,而不是以前的 MWE 中的单独编号。
Mico 的方法仍然有效。
\documentclass[11pt, a4paper, twoside]{book}
\RequirePackage[title,titletoc]{appendix}
% Mico's approach in https://tex.stackexchange.com/a/47011/87806
\usepackage{ifthen}
\makeatletter
%% For source of "@seccntformat" command, see book "The LaTeX Companion"
\def\@seccntformat#1{\@ifundefined{#1@cntformat}%
{\csname the#1\endcsname\ \ }% default
{\csname #1@cntformat\endcsname}}% enable individual control
%% Individual control: '\section@cntformat'
\newcommand{\section@cntformat}{\thechapter.\thesection\ \ }
% Macros to redefine numbering of appendix sections
\newcommand{\appname}{} % dummy definition
\newcommand{\appsecnumbering}[1][0]{%
\ifthenelse{#1=1}{\renewcommand\appname{Appendix}}
{\renewcommand\appname{Appendices}}
\setcounter{section}{0}
\renewcommand\thesection{\thechapter.\Alph{section}}
\renewcommand{\section@cntformat}{\appendixname~\thesection\ \ }
\addtocontents{toc}{\medskip\protect{\mdseries\appname\par}}}
\newcommand\normalsecnumbering{%
\renewcommand{\thesection}{\thechapter.\arabic{section}}
\renewcommand{\section@cntformat}{\thesection\ \ }}
\let\origchapter\chapter
\renewcommand\chapter{\normalsecnumbering % first, reset numbering style
\origchapter} % second, execute the original \chapter command
\makeatother
\begin{document}
\tableofcontents
\listoffigures
\listoftables
\chapter{First chapter}
\section{A section}
\appsecnumbering[1]
\section{First appendix}
\begin{table}[h!]
\begin{center}
\caption{A simple table.}
\label{tab:table1}
\begin{tabular}{l|c|r}
Value 1 & Value 2 & Value 3\\
\hline
1 & 1110.1 & a\\
2 & 10.1 & b\\
\end{tabular}
\end{center}
\end{table}
\chapter{Second chapter}
\section{A section}
\appsecnumbering[2]
\section{First appendix}
\section{Second appendix}
\end{document}