我的附录在后记中,在目录中,我只得到附录标题,并且我想在附录标题之前显示附录标签,例如
第 1 章...........XYZ
第 2 章...........ABC
附录 A..........X 的推导
附录 B..........Y 的推导
我尝试了针对此问题提供的解决方案,但似乎都不起作用。我正在使用 Texlive 2022(最新版)和 Texstudio(最新版本)。
另外,我希望附录采用一种与其他章节不同的新章节样式。可以吗?下图分别显示了我的问题和 MWE:
\documentclass[11pt,openany,twoside]{book}
\raggedbottom
\let\cleardoublepage=\clearpage
\usepackage[a4paper]{geometry}
\usepackage{parskip}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{amsthm}
\usepackage{array}
\usepackage{xcolor, graphicx}
\usepackage[dotinlabels]{titletoc}
\usepackage{background}
\backgroundsetup{contents={}}
\usepackage{helvet}
\usepackage{color}
\usepackage{fancyhdr}
\usepackage{hhline}
\pagestyle{fancy}
\usepackage{booktabs}
\usepackage[noindentafter,calcwidth]{titlesec}
\titleformat{\section}
{\normalfont\Large\bfseries\color{black}}
{\thesection}{1em}{}
\titleformat{\subsection}
{\normalfont\large\bfseries\color{black}}
{\thesubsection}{1em}{}
\usepackage{calc,pifont}
\usepackage{longtable}
\usepackage{multirow}
\usepackage{colortbl}
\newcommand*\myheaderfooterfont{\normalfont\bfseries}
\makeatletter
\renewcommand\@biblabel[1]
{\textsuperscript{#1}}
\makeatother
\usepackage[nottoc]{tocbibind}
\usepackage{verbatim}
\usepackage[ragged]{sidecap}
\usepackage{caption}
\captionsetup[table]{skip=5pt}
\usepackage[marginal]{footmisc}
\renewcommand\footnoterule{\vspace*{-3pt}%
\hrule width 2in height 1.4pt \vspace*{2.6pt}}
\setlength\footnotemargin{10pt}
\usepackage{tocloft}
\renewcommand{\cfttoctitlefont}{\hfill\normalfont\bfseries\huge}
\renewcommand{\cftloftitlefont}{\hfill\normalfont\bfseries\huge}
\renewcommand{\cftlottitlefont}{\hfill\normalfont\bfseries\huge}
\setlength{\cftbeforetoctitleskip}{-.3cm}
\setlength{\cftbeforeloftitleskip}{-.3cm}
\setlength{\cftbeforelottitleskip}{-.3cm}
\setlength{\cftafterloftitleskip}{1.7cm}
\setlength{\cftaftertoctitleskip}{1.4cm}
\setlength{\cftafterlottitleskip}{1.7cm}
\renewcommand{\cftchapfont}{\normalfont\bfseries}
\renewcommand{\cftsecfont}{\normalfont}
\renewcommand{\cftsubsecfont}{\normalfont}
\usepackage{etoolbox}
\usepackage{regexpatch}
\usepackage{listings}
\usepackage{float}
\captionsetup[table]{labelsep=period,indention=45pt,justification=raggedright}
\makeatletter
\pretocmd{\chapter}{\addtocontents{toc}{\protect\addvspace{-4\p@}}}{}{}
\makeatother
\renewcommand\cftchapafterpnum{\vskip-4pt}
\usepackage{hyperref}
\hypersetup{
colorlinks=true,
linkcolor=blue,
}
\usepackage[toc,header]{appendix}
\begin{document}
\frontmatter
{
\hypersetup{linkcolor=black}
\sffamily\tableofcontents
}
\titlecontents{chapter} [6pc]
{\addvspace{1pc}\normalfont\bfseries
\filright}
{\contentslabel
[\chaptername
\thecontentslabel]{6pc}}
{}{\hfill\contentspage}
[\addvspace{2pt}]
\mainmatter
\chapter{XYZ}
rhrrgrrgryryryfyfyfr
\chapter{ABC}
dgdegegegegeggdddrr
\backmatter
%\makeatletter
%\@mainmattertrue
%\makeatother
\begin{appendices}
\addtocontents{toc}{\protect\renewcommand{\protect\cftchappresnum}{Appendix }}
\renewcommand{\chaptername}{Appendix}
\chapter{Derivation of X}
The contents...
\chapter{Derivation of Y}
\end{appendices}
%\appendix
%\newappendix\label{firstappendix}
%\section{First section}
%This is Appendix~\ref{firstappendix}
%\newappendix\label{secondappendix}
%\section{Another section}
%This is Appendix~\ref{secondappendix}
\end{document}
答案1
文档前言中的代码相当复杂。就我所理解的程度而言,似乎各种指令相互矛盾或相互覆盖。我的两个主要建议,它们一起可以让你实现你所述的格式化目标,是
不要执行
\backmatter
,至少在附录之前不要执行。在之后重复该
\titlecontents
宏\begin{appendices}
,但现在使用Appendix
作为硬编码前缀字符串。
如果您不需要目录中的“附录”行,请toc
在加载appendices
包时省略该选项。
\documentclass[11pt,openany,twoside]{book}
\raggedbottom
\let\cleardoublepage\clearpage
\usepackage[a4paper]{geometry}
\usepackage{parskip}
\usepackage{amsmath}
%%\usepackage{amsfonts} % is loaded automatically by amssymb
\usepackage{amssymb}
\usepackage{amsthm}
\usepackage{array}
\usepackage[table]{xcolor} % note 'table' option (for 'colortbl')
\usepackage{graphicx}
\usepackage[dotinlabels]{titletoc}
\usepackage{background}
\backgroundsetup{contents={}}
\usepackage{helvet}
%%%\usepackage{color} % don't load both xcolor and color
\usepackage{fancyhdr}
\usepackage{hhline}
\pagestyle{fancy}
\usepackage{booktabs}
\usepackage[noindentafter,calcwidth]{titlesec}
\titleformat{\section}%
{\normalfont\Large\bfseries\color{black}}
{\thesection}{1em}{}
\titleformat{\subsection}%
{\normalfont\large\bfseries\color{black}}
{\thesubsection}{1em}{}
\usepackage{calc,pifont}
\usepackage{longtable}
\usepackage{multirow}
%%%\usepackage{colortbl} % don't load colortbl independently of xcolor
\newcommand*\myheaderfooterfont{\normalfont\bfseries}
\makeatletter
\renewcommand\@biblabel[1]{\textsuperscript{#1}}
\makeatother
\usepackage[nottoc]{tocbibind}
\usepackage{verbatim} % are you sure you need this package?
\usepackage[ragged]{sidecap}
\usepackage{caption}
\captionsetup[table]{skip=5pt}
\usepackage[marginal]{footmisc}
\renewcommand\footnoterule{\vspace*{-3pt}%
\hrule width 2in height 1.4pt \vspace*{2.6pt}}
\setlength\footnotemargin{10pt}
\usepackage{tocloft}
\renewcommand{\cfttoctitlefont}{\hfill\normalfont\bfseries\huge}
\renewcommand{\cftloftitlefont}{\hfill\normalfont\bfseries\huge}
\renewcommand{\cftlottitlefont}{\hfill\normalfont\bfseries\huge}
\setlength{\cftbeforetoctitleskip}{-.3cm}
\setlength{\cftbeforeloftitleskip}{-.3cm}
\setlength{\cftbeforelottitleskip}{-.3cm}
\setlength{\cftafterloftitleskip}{1.7cm}
\setlength{\cftaftertoctitleskip}{1.4cm}
\setlength{\cftafterlottitleskip}{1.7cm}
\renewcommand{\cftchapfont}{\normalfont\bfseries}
\renewcommand{\cftsecfont}{\normalfont}
\renewcommand{\cftsubsecfont}{\normalfont}
\renewcommand{\cftchapafterpnum}{\vskip-4pt}
\usepackage{etoolbox}
\usepackage{regexpatch}
\usepackage{listings}
\usepackage{float}
\captionsetup[table]{labelsep=period, indention=45pt,
justification=raggedright}
\makeatletter
\pretocmd{\chapter}{\addtocontents{toc}{\protect\addvspace{-4\p@}}}{}{}
\makeatother
\usepackage{hyperref}
\hypersetup{
colorlinks=true,
linkcolor=blue,
}
\usepackage[toc,header]{appendix}
\begin{document}
\frontmatter
{
\hypersetup{linkcolor=black}
\sffamily
\tableofcontents
}
\titlecontents{chapter}[7pc]
{\addvspace{1pc}\normalfont\bfseries
\filright}
{\contentslabel
[Chapter \thecontentslabel]{7pc}}
{}{\hfill\contentspage}
[\addvspace{2pt}]
\mainmatter
\chapter{XYZ}
rhrrgrrgryryryfyfyfr
\chapter{ABC}
dgdegegegegeggdddrr
\begin{appendices}
%\addtocontents{toc}{\protect\renewcommand{\protect\cftchappresnum}{Appendix }}
%% Rerun the \titlecontents macro, but now with 'Appendix' prefix string
\titlecontents{chapter}[7pc]
{\addvspace{1pc}\normalfont\bfseries
\filright}
{\contentslabel
[Appendix \thecontentslabel]{7pc}}
{}{\hfill\contentspage}
[\addvspace{2pt}]
\chapter{Derivation of X}
The contents\dots
\chapter{Derivation of Y}
\end{appendices}
\end{document}