我想在文档主体中引用附录中的不同小节。我在\label{}
每个小节开头后都使用了,但是当我使用\ref{thatlabel}
简单时,它给出的数字并不指向附录中的小节。
我的阑尾:
\appendix
\section*{Appendix 4}
\addcontentsline{toc}{section}{Appendix 4}
In our thesis, we have used extensively the programming language Python to create, prepare and analyze our data set. This appendix contains the most important scripts we have used. Each script is accompanied by a short description that explains the main features and the results it provides.
\addcontentsline{toc}{subsection}{5.1 Downloading the .zip files containing the EDGAR logs}
\subsection*{4.1 Downloading the .zip files containing the EDGAR logs}
\label{Appendix.DownloadingZipFiles}
To download the .zip files, which we use for calculating the SBP scores, from the Edgar website, we used the "Logfile List" available here: https://www.sec.gov/dera/data/edgar-log-file-data-set.html. The file contains links to each individual .zip.
\lstinputlisting[language=Python]{./Code/get_zip_files.py}
\addcontentsline{toc}{subsection}{4.2 Downloading the form types files}
\subsection*{4.2 Downloading the form types files}
\label{Appendix.DownloadingFormTypes}
We need to have a database with the form types corresponding to each accession number. This allows us to select only the relevant form types for the analysis. The code below, downloads those form types from the Edgar' master index.
\lstinputlisting[language=Python]{./Code/get_form_files.py}
\addcontentsline{toc}{subsection}{4.3 Calculation of the Annual Search Fractions}
\label{Appendix4.1:AnnualSearchFrac}
\subsection*{4.3 Calculation of the Annual search fractions}
The following script is one the largest and most complex script we have used. It calculates the ASF scores for the SBP selection scheme.
\lstinputlisting[language=Python]{./Code/SBP_frac_theis.py}
\addcontentsline{toc}{subsection}{4.4 Creation of the trailing accounts for our database}
\subsection*{4.4 Creation of the trailing accounts for our database}
\label{Appendix.CreatingTrailingAccounts}
The script takes the raw quarterly fundamentals from WRDS. We downloaded the quarterly fundamentals for the firms belonging to the S\&P1500 index from Compustat/North America - Annual Updates/Fundamentals Quarterly/ and transformed them into the trailing accounting data that we use in our analysis.
\lstinputlisting[language=Python]{./Code/read_csv.py}
\break
\addcontentsline{toc}{subsection}{5.5 Creation of the peer groups based on SBP}
\subsection*{4.5 Creation of the peer groups based on SBP}
\label{Appendix.CreatingPeerGroupsSBP}
The code below, takes the 3 inputs: the trailing accounts database, the index constituents and the annual search fractions. Using these 3 inputs, the it can create peer groups of different sizes.
\lstinputlisting[language=Python]{./Code/SBP_peer_groups.py}
\addcontentsline{toc}{subsection}{4.6 Creation of the peer groups based on GICS}
\subsection*{4.6 Creation of the peer groups based on GICS}
\label{Appendix.CreatingPeerGroupsGICS}
例如,如果我尝试引用,\label{Appendix.DownloadingZipFiles}
它会显示数字 7。有没有适当的方法来引用附录中的子部分?谢谢!
答案1
当您使用 a\section*
或\subsection*
命令时,不会设置内部标签值。这样做是因为 a(sub)section*
没有数字,因此无法通过该数字引用它。相反,如果代码包含命令\label
,则会使用最后一个已知数字,这显然是错误的。在当前问题的情况下,数字是手动添加的,因此可以引用它,但这需要手动设置内部标签值。
在下面的 MWE 中,\apxsub
定义了一个新命令来替代\subsection
。这个新命令有三个参数:编号、标题和参考标识符。该命令创建一个\subsection*
,添加一个内容行,设置内部\@currentlabel
值并创建标签。该命令包含在\makeatletter
和中,\makeatother
因为 中有一个 at 符号 ( @
) ,这意味着除非将字符视为普通字符(这就是所做的),否则\@currentlabel
无法访问此宏。对应方随后恢复字符的特殊状态。@
\makeatletter
\makeatother
@
代码:
\documentclass{article}
\begin{document}
\makeatletter
\newcommand{\apxsub}[3]{%
\subsection*{#1 #2}
\addcontentsline{toc}{subsection}{#1 #2}
\def\@currentlabel{#1}%
\label{#3}%
}
\makeatother
\tableofcontents
\section{Normal section}
See also subsection \ref{sec:sub41} in the appendix.
\appendix
\section*{Appendix 4}
\addcontentsline{toc}{section}{Appendix 4}
\apxsub{4.1}{Downloading}{sec:sub41}
Some text
\end{document}
结果:
但是,这个问题看起来像 Stack Exchange 网站上所谓的 XY 问题:您尝试使用解决方案 Y 解决问题 X,Y 存在问题,因此您询问这些问题,而更好的方法是解决 X。在这种情况下,问题 X 是您不喜欢附录部分的默认外观,即A Some Title
等B Some other title
。解决这个问题的尝试是使用带星号的部分和小节,但额外的问题是这些部分无法引用。相反,更好的解决方案是更改附录标题的外观并使用常规(非星号)部分,这些部分会自动包含在目录中并且可以引用。
这appendix
软件包可以在一定程度上帮助解决这个问题,它提供了将单词附录(或其他单词)放在章节标题前面。要将编号从字母更改为数字,您可以自己重新定义编号宏。请注意,此方法不使用开关,\appendix
而是使用环境\begin{appendices}\end{appendices}
。
代码:
\documentclass{article}
\usepackage[titletoc,title]{appendix}
\begin{document}
\tableofcontents
\section{Normal section}
See also subsection \ref{sec:sub41} in the appendix.
\begin{appendices}
\setcounter{section}{3} % skip first three appendices
\renewcommand*{\thesection}{\arabic{section}} % redefine section numbering from letters to digits
\section{}
\subsection{Downloading}
\label{sec:sub41}
Some text
\end{appendices}
\end{document}
结果与上面相同。