我有一個客製化的附錄部分,其中包括幾個不同的附錄,例如附錄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
使用\label
without\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}