我使用appendix
包来生成附录。它在文本中生成所需的标题,但在目录中生成附录条目的方式与生成章节条目的方式完全相同。但是,我希望这有所不同。特别是,我希望附录条目是
\cftchappresnum
(我不想设置为,而是\chaptername
想将其设置为全大写的“附录”)。但是,对于使用以下语法的附录,我似乎无法做到这一点
\begin{appendices}
\chapter{}
\end{appendices}
通过上述语法,我只是得到了阿拉伯数字,并使用单词“章节”而不是附录。
因此,我习惯于\chapter*
完全避免打印目录中的章节条目,但随后添加自定义代码来生成我想要的输出,如下所示
\AtBeginEnvironment{appendices}{\renewcommand{\thesection}{\arabic{appendix}.\arabic{section}.}}
\newcommand{\appendixtitle}{}
\newcommand{\appendixtitleFull}{\chaptername\space\Alph{appendix}.\space\uppercase{\appendixtitle}}
\newlength{\widthAppendixName}
\setlength{\widthAppendixName}{\widthof{\chaptername \Alph{appendix}.~~} - \cftsecindent}
\makeatletter
\AtBeginEnvironment{appendices}{
\preto{\chapter}{
\addtocounter{appendix}{1}
\setcounter{section}{0}
\setcounter{figure}{0}
\setcounter{equation}{0}
\addtocounter{appendix}{1}
\addtocontents{toc}{\protect
\contentsline{chapter}{\numberline{\chaptername~\Alph{appendix}.}%
\cftchapaftersnumb\hspace{\widthAppendixName}\uppercase{\appendixtitle}%
}{\thepage}{\@currentHref}
}
}
}
\makeatother
但是,使用上面的代码,我得到了错误的页码和错误的超链接目标。有没有办法在使用生成附录的正常机制(即使用附录环境和 \chapter 命令)的同时获得我想要的输出?
答案在目录中附录的页码错误
不适合这里,因为我使用的是appendices
包而不是一般\appendix
命令。答案在目录和附录没有显示如何使附录条目与章节不同,同时在目录中维护正确的页面文档。
\documentclass[11pt,a4paper,oneside]{book}
\usepackage[x11names]{xcolor}
\usepackage{calc}
\usepackage{caption}
\usepackage{graphicx}
\usepackage{etoolbox}
\usepackage{tocloft}
\usepackage{tocloft}
% BEGIN_FOLD
% Labels widths
\setlength{\cftchapnumwidth}{\widthof{\chaptername .~~}}
\newlength{\widthcftsecnumwidth}
\setlength{\widthcftsecnumwidth}{\widthof{1.2.3~}}
\setlength{\cftsecnumwidth}{\widthcftsecnumwidth}
% Labels indentations
\newlength{\widthSpace}
\setlength{\widthSpace}{\widthof{~}}
\setlength{\cftchapindent}{0mm}
\setlength{\cftsecindent}{\widthof{\chaptername 1.~} - 0.5\widthSpace - \widthcftsecnumwidth}
\setlength{\cftsubsecindent}{\cftsecindent + \widthof{\cftsecaftersnumb} + \cftsecnumwidth}
\newcommand{\tocchapfont}{}
\renewcommand{\cftchapfont}{\tocchapfont}
% END_FOLD
\usepackage{appendix}
\newcounter{appendix}
\AtBeginEnvironment{appendices}{\renewcommand{\thefigure}{\Alph{appendix}.\arabic{figure}.}}
\AtBeginEnvironment{appendices}{\renewcommand{\thetable}{\Alph{appendix}.\arabic{table}.}}
\AtBeginEnvironment{appendices}{\renewcommand{\theequation}{\Alph{appendix}.\arabic{equation}}}
\AtBeginEnvironment{appendices}{\renewcommand{\chaptername}{APPENDIX}}
\AtBeginEnvironment{appendices}{\renewcommand{\thesection}{\arabic{appendix}.\arabic{section}.}}
% Define new way to add appendices to the TOC
\newcommand{\appendixtitle}{}
\newcommand{\appendixtitleFull}{\chaptername\space\Alph{appendix}.\space\uppercase{\appendixtitle}}
\newlength{\widthAppendixName}
\setlength{\widthAppendixName}{\widthof{\chaptername \Alph{appendix}.~~} - \cftsecindent}
\makeatletter
\AtBeginEnvironment{appendices}{
\preto{\chapter}{
\setcounter{section}{0}
\addtocounter{appendix}{1}
\addtocontents{toc}{\protect
\contentsline{chapter}{\numberline{\chaptername~\Alph{appendix}.}%
\cftchapaftersnumb\hspace{\widthAppendixName}\uppercase{\appendixtitle}%
}{\thepage}{\@currentHref}
}
}
}
\makeatother
\usepackage{hyperref}
\hypersetup{citecolor=DodgerBlue3, citebordercolor=DodgerBlue3, urlcolor=Blue1, colorlinks=true}
\newcommand{\sampleEquationFloats}{
\begin{figure}
\includegraphics[]{example-image-a}
\caption{Figure Caption}
\end{figure}
\begin{equation}
E = m c^{2}
\end{equation}
\begin{table}
\caption{Table Caption}
\centering
\begin{tabular}{|c |c|}
\hline
Column & Column
\\
\hline
\end{tabular}
\end{table}
}
\begin{document}
\tableofcontents
\chapter{subappendices}
\sampleEquationFloats
\newpage
\section{Section 1}
\begin{subappendices}
\section{Appendix 1.A}
\sampleEquationFloats
\section{Appendix 1.B}
\sampleEquationFloats
\section{Appendix 1.C}
\end{subappendices}
\section{Section 2}
\newpage
\sampleEquationFloats
\begin{appendices}
\renewcommand{\appendixtitle}{My Title}
\chapter*{\appendixtitleFull}
\sampleEquationFloats
\section{One Section}
\section{Another Section}
\renewcommand{\appendixtitle}{My Title}
\chapter*{\appendixtitleFull}
\sampleEquationFloats
\section{One Section}
\section{Another Section}
\renewcommand{\appendixtitle}{My Title}
\chapter*{\appendixtitleFull}
\sampleEquationFloats
\section{One Section}
\section{Another Section}
\end{appendices}
\chapter{New Chapter}
\section{New Section}
\begin{subappendices}
\section{Appendix A}
\sampleEquationFloats
\section{Appendix B}
\sampleEquationFloats
\section{Appendix C}
\end{subappendices}
\end{document}