附录和交叉引用

附录和交叉引用

首先是我的代码:(我添加了我目前正在使用的所有包)

\documentclass[12pt,a4paper,notitlepage]{report}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage[round]{natbib}
\usepackage{graphicx}
\usepackage{pdfpages}
\usepackage[toc,page]{appendix}
\usepackage[onehalfspacing]{setspace}
\usepackage{hyperref}
\usepackage{chngcntr}
\usepackage{tabularx}
\usepackage{adjustbox}
\usepackage{array,booktabs}
\usepackage{multirow}
\usepackage{bm}
\usepackage{setspace}
\usepackage{threeparttable}


\begin{document}

\chapter{Text}

Here is a chapter with text where I want to make a reference to Appendix A. Lets try the reference: Here a reference to Appendix \ref{appendix:a} and a reference to Appendix B namely Appendix \ref{appendix:b}.

\appendix
\chapter{Appendix A}
\label{appendix:a}
This is the content of the appendix A. 
\chapter*{Appendix B}
\label{appendix:b}
This is the content of the appendix B.

\end{document}

本例对 的引用非常完美Appendix A。但是, 的标题Appendix A出现了两次。一次是由于\chapter{Appendix A},一次是由于 是\chapter{Appendix A}附录的第一个条目。此外,\appendix将数字引用更改为字母引用。

显然,添加*附录 B 会删除额外的标题,从而使得正确的引用变得不可能。

有人知道如何处理这个问题吗?

我已经尝试过了\begin{appendices} ... \end{appendices},但是,对于该版本,附录章节的编号是数字,而不是“A,B等”

编辑:我希望目录不包括附录章节,附录中只包含章节名称。但是,如前所述,使用\chapter*{chapter_name}会导致引用不可用。

\documentclass[12pt,a4paper,notitlepage]{report}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage[round]{natbib}
\usepackage{graphicx}
\usepackage{pdfpages}
\usepackage[toc,page]{appendix}
\usepackage[onehalfspacing]{setspace}
\usepackage{hyperref}
\usepackage{chngcntr}
\usepackage{tabularx}
\usepackage{adjustbox}
\usepackage{array,booktabs}
\usepackage{multirow}
\usepackage{bm}
\usepackage{setspace}
\usepackage{threeparttable}


\begin{document}
 \tableofcontents
\chapter{Text}

Here is a chapter with text where I want to make a reference to Appendix A. Lets try the reference: Here a reference to Appendix \ref{appendix:a} and a reference to Appendix B namely Appendix \ref{appendix:b}.

 \begin{appendices}
 \chapter*{Appendix A}
 \label{appendix:a}
 This is the content of the appendix A. 
 \chapter*{Appendix B}
 \label{appendix:b}
 This is the content of the appendix B.
\end{appendices}
\end{document}

答案1

重复Appendix A等是由于错误使用\chapter{Appendix A}-- 但可以删除(但如果可以自动完成,为什么要这样命名?) -- 无论如何,我\chaptername通过重新定义删除了章节标题的标题行\@makechapterhead

环境启动后,ToC可以使用来删除附录章节。\addtocontents{toc}{\protect\setcounter{tocdepth}{-2}}appendices

\documentclass[12pt,a4paper,notitlepage]{report}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage[round]{natbib}
\usepackage{graphicx}
\usepackage{pdfpages}
\usepackage[toc,page]{appendix}
\usepackage[onehalfspacing]{setspace}
\usepackage{chngcntr}
\usepackage{tabularx}
\usepackage{adjustbox}
\usepackage{array,booktabs}
\usepackage{multirow}
\usepackage{bm}
\usepackage{setspace}
\usepackage{threeparttable}

\usepackage{xpatch}
\usepackage{hyperref}

\makeatletter
\AtBeginEnvironment{appendices}{%
  % Removing the entries to the toc within appendices environment with \setcounter{tocdepth}{-2}
  \addtocontents{toc}{\protect\setcounter{tocdepth}{-2}}
  % Removing the \chaptername header line in the chapter head command \@makechapterhead
  \def\@makechapterhead#1{%
    \vspace*{50\p@}%
    {\parindent \z@ \raggedright \normalfont
      % \ifnum \c@secnumdepth >\m@ne
      % \huge\bfseries \@chapapp\space \thechapter
      % \par\nobreak
      % \vskip 20\p@
      % \fi
    \interlinepenalty\@M
    \Huge \bfseries #1\par\nobreak
    \vskip 40\p@
  }}
}
\makeatother

\begin{document}
 \tableofcontents
\chapter{Text}

Here is a chapter with text where I want to make a reference to Appendix A. Lets try the reference: Here a reference to Appendix \ref{appendix:a} and a reference to Appendix B namely Appendix \ref{appendix:b}.




\begin{appendices}
  \chapter{Appendix A}
  \label{appendix:a}
  This is the content of the appendix A. 
  \chapter{Appendix B}
  \label{appendix:b}
  This is the content of the appendix B.
\end{appendices}
\end{document}

相关内容