引用附录中的非图形

引用附录中的非图形

我有一个自定义的附录部分,其中包含几个不同的附录,例如附录 A、附录 B 等。在每个附录中,我都有表格、图形,有时还有从 PDF 中摘录的页面(不是图形),因此我不会为它们添加标题,而是为它们提供一个自定义部分标题,该标题不会出现在目录中。这是一个 MWE。

\documentclass[12pt, a4paper]{memoir}
\usepackage[utf8]{inputenc}
\usepackage[dvips]{graphicx} % to include images
\usepackage[bookmarksnumbered, breaklinks=true,colorlinks=true, linkcolor=black, urlcolor=blue, citecolor=blue, bookmarks=true]{hyperref}
\usepackage[nameinlink,noabbrev]{cleveref}
\crefname{page}{p.}{pp.}
\crefname{figure}{figure}{figures}

\settypeblocksize{237mm}{150mm}{*} % size of text block on page
\setulmargins{3.5cm}{*}{*} % sets start of text on page after ruled header
\setheadfoot{\onelineskip}{2\onelineskip}
\setheaderspaces{2cm}{*}{*} % start of rule header line on page
\setlrmarginsandblock{3.5cm}{2.5cm}{*} % left and right margins
\checkandfixthelayout

%%% MAKE CHAPTER IN APPENDIX LOOK LIKE SECTIONS
\cftinsertcode{APP}{
  \setlength\cftchapterindent{\cftsectionindent}
  \setlength\cftbeforechapterskip{0pt}
  \renewcommand*{\cftappendixname}{\appendixname\space}
  \renewcommand{\cftchapteraftersnum}{:}
  \renewcommand\cftchapterdotsep{\cftdotsep} % Chapters should use dots in ToC
  \renewcommand\cftchapterfont{\normalfont}
  \renewcommand\cftchapterpagefont{\normalfont}
}

%%% PREVENT APPENDIX SECTIONS TO BE ADDED TO TOC
\newcommand{\nocontentsline}[3]{}
\newcommand{\tocless}[2]{\bgroup\let\addcontentsline=\nocontentsline#1{#2}\egroup}

%%% CUSTOM CHAPTER STYLE FOR APPENDICES
\makechapterstyle{appendix}{%
  \chapterstyle{default}
  \setlength{\beforechapskip}{3.5ex}
  \renewcommand*{\chapterheadstart}{\vspace{\beforechapskip}}
  \setlength{\afterchapskip}{2.3ex}
  \renewcommand{\chapnumfont}{\normalfont\bfseries\Large}
  \renewcommand{\chapnamefont}{\normalfont\bfseries\Large}
  \renewcommand{\chaptitlefont}{\normalfont\bfseries\Large}
  \renewcommand{\printchapternum}{\chapnumfont~\thechapter}
  \renewcommand{\afterchapternum}{:\space}
}

\renewcommand{\contentsname}{Table of Contents}
\maxsecnumdepth{subsubsection} % chapters, sections, subsections numbered
\maxtocdepth{subsection}

\begin{document}

% TABLE OF CONTENTS
\SingleSpacing
\tableofcontents*
\clearpage % Force a break to new page

\chapter{Chapter title}
\section{A first section title}
\section{A second section title}
Just some text. I'd like to reference Appendix A2 here by doing (see \Cref{appendix:A2}, \cpageref{appendix:A2}), but it only references to A not to A2.

\appendix
\appendixpage % cover page appendix
\cftinserthook{toc}{APP}
\chapterstyle{appendix}

%appendix A content
\chapter{Some title for first appendix}
\label{appendix:A}

\tocless\section{Information Form - Page 1/2}
\begin{figure}[!htb]
\label{appendix:A1}
\fbox{\includegraphics[page=1,width=14.5cm]{info.pdf}}
\end{figure}

\tocless\section{Information Form - Page 2/2}
\begin{figure}[!htb]
\label{appendix:A2}
\fbox{\includegraphics[page=2,width=14.5cm]{info.pdf}}
\end{figure}

\chapter{Some title for next appendix}
\label{appendix:B}
Nothing here yet.

\end{document}

编译后的样子如下示例 PDF... 我的问题是,我想在文中引用附录 A2。目前引用的是附录 A,但应该是附录 A2。有什么建议可以实现这一点吗?谢谢。

答案1

在这里使用\labelwithout\caption是没用的,因为它需要\refstepcounter预先输入命令,而这由 \caption 内部完成,也就是说,手册\refstepcounter{figure}\label{...}应该可以解决这两个例子中的问题,但是,如果您有更多这样的无标题的“假”部分,这可能会变得乏味。

\documentclass[12pt, a4paper]{memoir}
\usepackage[utf8]{inputenc}
\usepackage[demo]{graphicx} % to include images
\usepackage[bookmarksnumbered, breaklinks=true,colorlinks=true, linkcolor=black, urlcolor=blue, citecolor=blue, bookmarks=true]{hyperref}
\usepackage[nameinlink,noabbrev]{cleveref}
\crefname{page}{p.}{pp.}
\crefname{figure}{figure}{figures}

\settypeblocksize{237mm}{150mm}{*} % size of text block on page
\setulmargins{3.5cm}{*}{*} % sets start of text on page after ruled header
\setheadfoot{\onelineskip}{2\onelineskip}
\setheaderspaces{2cm}{*}{*} % start of rule header line on page
\setlrmarginsandblock{3.5cm}{2.5cm}{*} % left and right margins
\checkandfixthelayout

%%% MAKE CHAPTER IN APPENDIX LOOK LIKE SECTIONS
\cftinsertcode{APP}{
  \setlength\cftchapterindent{\cftsectionindent}
  \setlength\cftbeforechapterskip{0pt}
  \renewcommand*{\cftappendixname}{\appendixname\space}
  \renewcommand{\cftchapteraftersnum}{:}
  \renewcommand\cftchapterdotsep{\cftdotsep} % Chapters should use dots in ToC
  \renewcommand\cftchapterfont{\normalfont}
  \renewcommand\cftchapterpagefont{\normalfont}
}

%%% PREVENT APPENDIX SECTIONS TO BE ADDED TO TOC
\newcommand{\nocontentsline}[3]{}
\newcommand{\tocless}[2]{\bgroup\let\addcontentsline=\nocontentsline#1{#2}\egroup}

%%% CUSTOM CHAPTER STYLE FOR APPENDICES
\makechapterstyle{appendix}{%
  \chapterstyle{default}
  \setlength{\beforechapskip}{3.5ex}
  \renewcommand*{\chapterheadstart}{\vspace{\beforechapskip}}
  \setlength{\afterchapskip}{2.3ex}
  \renewcommand{\chapnumfont}{\normalfont\bfseries\Large}
  \renewcommand{\chapnamefont}{\normalfont\bfseries\Large}
  \renewcommand{\chaptitlefont}{\normalfont\bfseries\Large}
  \renewcommand{\printchapternum}{\chapnumfont~\thechapter}
  \renewcommand{\afterchapternum}{:\space}
}

\renewcommand{\contentsname}{Table of Contents}
\maxsecnumdepth{subsubsection} % chapters, sections, subsections numbered
\maxtocdepth{subsection}

\begin{document}

% TABLE OF CONTENTS
\SingleSpacing
\tableofcontents*
\clearpage % Force a break to new page

\chapter{Chapter title}
\section{A first section title}
\section{A second section title}
Just some text. I'd like to reference Appendix A2 here by doing (see \Cref{appendix:A2}, \cpageref{appendix:A2}), but it only references to A not to A2.

\appendix
\appendixpage % cover page appendix
\cftinserthook{toc}{APP}
\chapterstyle{appendix}

%appendix A content
\chapter{Some title for first appendix}
\label{appendix:A}

\tocless\section{Information Form - Page 1/2}
\begin{figure}[!htb]
\refstepcounter{figure}%
\label{appendix:A1}
\fbox{\includegraphics[page=1,width=14.5cm]{info.pdf}}
\end{figure}

\tocless\section{Information Form - Page 2/2}
\begin{figure}[!htb]
\refstepcounter{figure}%
\label{appendix:A2}
\fbox{\includegraphics[page=2,width=14.5cm]{info.pdf}}
\end{figure}

\chapter{Some title for next appendix}
\label{appendix:B}
Nothing here yet.

\end{document}

相关内容