我有一个包含章节的附录,例如section*{Appendix 1: Measurment of X.Y.}
。我已用设置了标签\label{appendix:1}
。现在,如果我通过引用该附录,\ref{appendix:1}
我会得到附录前最后一个编号章节的编号。这是因为我的附录也是一个未编号的章节。在我的文本中,我希望显示附录的编号(每个章节*在这里都是一个新的附录),例如“在附录 3 中您可以看到...”。我该怎么做?
编辑:这是MWE:
\documentclass[
paper=a4,
twoside=true,
open=right,
fontsize=12pt,
parskip,
headsepline,
cleardoublepage=empty,
]{scrbook}
\usepackage{scrpage2}
\pagestyle{scrheadings}
\automark[section]{chapter}
\clearscrheadings
\ihead{}
\chead{}
\ohead{\headmark}
\ifoot{}
\cfoot{}
\clearscrplain
\ofoot[\pagemark]{\pagemark}
\setlength{\headheight}{1.1\baselineskip}
\usepackage[latin1]{inputenc}
\usepackage[
backend=bibtex,
]{biblatex}
\usepackage[pdftex,
colorlinks,
linkcolor = black]{hyperref}
\usepackage[titletoc,title]{appendix}
\begin{document}
\tableofcontents
\chapter{Just a chapter}
Blabla
\chapter{Just another chapter}
Bla, bla, see appendix \ref{appendix:1}. Here should be a 1 for the first appendix and not the 2 for the last numbered chapter.
\chapter*{Appendix}
\begin{appendix}
\renewcommand{\thesection}{Anhang \arabic{section}:}
\addcontentsline{toc}{chapter}{Appendix}
\newpage
\section*{Appendix 1: Measurement X.Y.} \label{appendix:1}
\addcontentsline{toc}{section}{Appendix 1: Measurement X.Y.}
\chaptermark{Appendix}
\end{appendix}
\end{document}
答案1
如果坚持\section*
,那么稍微重新定义\section*
命令会有所帮助,但在我的这种情况下,它总是会自动添加 TOC 条目。
我放弃了,\begin{appendix}...\end{appendix}
因为在我看来它基本上没有任何好处。
页面样式可以随意改变。
\documentclass[
paper=a4,
twoside=true,
open=right,
fontsize=12pt,
parskip,
headsepline,
cleardoublepage=empty,
]{scrbook}
%\usepackage{etoolbox}%
\usepackage{blindtext}
\usepackage{scrpage2}
\pagestyle{scrheadings}
\automark[section]{chapter}
\clearscrheadings
\ihead{}
\chead{}
\ohead{\headmark}
\ifoot{}
\cfoot{}
\clearscrplain
\ofoot[\pagemark]{\pagemark}
\setlength{\headheight}{1.1\baselineskip}
\usepackage[latin1]{inputenc}
\usepackage[
backend=bibtex,
]{biblatex}
\usepackage[pdftex,
colorlinks,
linkcolor = black]{hyperref}
\usepackage[titletoc,title]{appendix}
\newcounter{starredsection}[chapter]
\makeatletter
\let\LaTeXStandardsection\section
\newcommand{\unstarred@@section@@noopt}[1]{%
\unstarred@@section@@opt[#1]{#1}%
}%
\newcommand{\unstarred@@section@@opt}[2][]{%
\LaTeXStandardsection[#1]{#2}%
}%
\newcommand{\unstarredsection}{%
\@ifnextchar[{\unstarred@@section@@opt}{\unstarred@@section@@noopt}%
}%
\newcommand{\starredsection}[1]{%
\refstepcounter{starredsection}%
\LaTeXStandardsection*{#1}%
\addcontentsline{toc}{section}{\protect\numberline{}#1}%
}%
\renewcommand{\section}{%
\@ifstar{\starredsection}{\unstarredsection}%
}%
\begin{document}
\tableofcontents
\chapter{Just a chapter}
Blabla
\chapter{Just another chapter}
Bla, bla, see appendix \ref{appendix:1}. Here should be a 1 for the first appendix and not the 2 for the last numbered chapter. But here will be 2 because, it's a reference to appendix \ref{appendix:2}%
\pagestyle{plain}
\clearscrheadings
\clearscrplain
\pagestyle{scrheadings}%
\lehead{\appendixname~\thestarredsection}
\chapter*{\appendixname}
%\begin{appendix}
%\chaptermark{Appendix}
\renewcommand{\thesection}{Anhang \arabic{section}:}
\addcontentsline{toc}{chapter}{Appendix}
%\newpage
\section*{Appendix 1: Measurement X.Y.} \label{appendix:1}
%\addcontentsline{toc}{section}{Appendix 1: Measurement X.Y.}
%\end{appendix}
\blindtext
\section*{Appendix 2: Measurement Y.Z } \label{appendix:2}
\blindtext[2]
\end{document}
答案2
您应该使用\section
而不是\section*
。这是一个可能的解决方案,假设您没有\subsection
附录中的命令。如果有,安排它们并不困难,只是稍微复杂一些。
\documentclass[
paper=a4,
twoside=true,
open=right,
fontsize=12pt,
parskip,
headsepline,
cleardoublepage=empty,
]{scrbook}
\usepackage{scrpage2}
\pagestyle{scrheadings}
\automark[section]{chapter}
\clearscrheadings
\ihead{}
\chead{}
\ohead{\headmark}
\ifoot{}
\cfoot{}
\clearscrplain
\ofoot[\pagemark]{\pagemark}
\setlength{\headheight}{1.1\baselineskip}
\usepackage[latin1]{inputenc}
\usepackage[
backend=bibtex,
]{biblatex}
\usepackage[
colorlinks,
linkcolor = black
]{hyperref}
\usepackage[titletoc,title]{appendix}
\begin{document}
\tableofcontents
\chapter{Just a chapter}
Blabla
\chapter{Just another chapter}
Bla, bla, see appendix \ref{appendix:1}. Here should be a 1 for the first appendix
and not the 2 for the last numbered chapter.
\chapter*{Appendix}
\addcontentsline{toc}{chapter}{Appendix}
\chaptermark{Appendix}
\renewcommand{\thesection}{\arabic{section}}
\begin{appendix}
\makeatletter
\renewcommand{\@seccntformat}[1]{Appendix \csname the#1\endcsname: }
\makeatother
\section{Measurement X.Y.} \label{appendix:1}
\end{appendix}
\end{document}
参考资料
附录
答案3
如果你认为这是错误的做法。你的不同附录应该与文档的其余部分具有相同的级别,即章节.因此最干净的解决方案是使用
部分来表示你的附录(如果你真的想这样做)。随着编号方案从arabic
变为Alph
期望那里发生一些事情。不需要一个大的嘿,大家看,阑尾从这里开始。
看看下面的两个解决方案,它们不需要任何麻烦。
毕竟,这更多的是一个风格问题,而不是 LaTeX 实现的问题。
\documentclass{scrbook}
\begin{document}
\tableofcontents
\chapter{Polishing eggs}
See appendix \ref{app:measurement} for further information.
Especially \ref{app:measurement:xy}
\appendix
%\addcontentsline{toc}{part}{\appendixname}%
%This would be the clean solution
\chapter{Measurements}
\label{app:measurement}
\section{LASER things}
\label{app:measurement:xy}
\section{Plasma stuff}
\chapter{Third party data}
\end{document}
以下是目录的输出:
这是另一个解决方案,但不如之前的解决方案那么简洁。不过,我们还是继续吧:
\documentclass{scrbook}
\begin{document}
\tableofcontents
\chapter{Polishing eggs}
See appendix \ref{app:measurement:xy} for further information.
\appendix
\addchap{Appendix}
\renewcommand{\thesection}{\arabic{section}}
\section{Measurement LASER things}
\label{app:measurement:xy}
\section{Measurement Plasma stuff}
\end{document}