为了遵守学校的规定,我必须不是打印章节标题并对目录和章节进行一些其他更改。以下是(或多或少最小的)MWE:
\documentclass[titlepage, headsepline, toc=sectionentrywithdots, listof=entryprefix, parskip=half-]{scrartcl}
\usepackage[english]{babel}
\providecaptionname{english}{\listofatocentryname}{App.}
\usepackage{hyperref}
\makeatletter
\AfterTOCHead[atoc]{\let\if@dynlist\if@tocleft}
\newcommand*{\useappendixtocs}{
\renewcommand*{\ext@toc}{atoc}
\RedeclareSectionCommands[tocindent=0pt]{section, subsection, subsubsection}
\RedeclareSectionCommands[tocnumwidth=85pt]{section, subsection, subsubsection}
\addtokomafont{sectionentry}{\mdseries}
\renewcommand*\listoflofentryname{\mdseries}
\renewcommand{\thesection}{\arabic{section}}
\renewcommand{\@dotsep}{10000}
}
\newcommand*{\usestandardtocs}{
\renewcommand*{\ext@toc}{toc}
}
\makeatother
\usepackage[automark]{scrlayer-scrpage}
\pagestyle{scrheadings}
\DeclareNewTOC[%
tocentrystyle=tocline,
tocentryentrynumberformat=\PrefixBy{App.},
listname={Appendix}%
]{atoc}
\usepackage{xpatch}
\xapptocmd\appendix{%
\useappendixtocs
\listofatocs
\addcontentsline{toc}{section}{Appendix}
\newpage
\pagenumbering{gobble}
\pagestyle{scrheadings}
\clearmainofpairofpagestyles
\clearplainofpairofpagestyles
\rohead{\textnormal{App.~\arabic{section}}}
\lohead{\textnormal{\currentname}}
}{}{}
\begin{document}
\tableofcontents
\section{Test1}
This is a reference to appendix \ref{sec:app2} with the name \nameref{sec:app2}.
At this point, reference is made to Annex 2.
The number is correct, but nameref outputs the wrong name.
\clearpage
\appendix
\clearpage
\renewcommand{\section}[1]{
\par\refstepcounter{section}
\sectionmark{#1}
\addcontentsline{atoc}{section}{\bfseries\protect\numberline{\thesection}{\mdseries#1}}
\lohead{\textnormal{#1}}
}
\section{First Appendix}
\label{sec:app1}
Appendix 1
\clearpage
\section{Second Appendix}
\label{sec:app2}
Appendix 2
\end{document}
如您所见,由于附录中的部分命令的更新,nameref
它不再起作用:
我怎样才能解决这个nameref
问题或者实现我的目标,即附录看起来像这样:
在某种程度上,这不会破坏 nameref?
答案1
您需要存储标题:
\documentclass[parskip=half-]{scrartcl}
\usepackage[automark]{scrlayer-scrpage}
\usepackage[english]{babel}
\usepackage{hyperref}
\begin{document}
\section{Test1}
This is a reference to appendix \ref{sec:app2} with the name \nameref{sec:app2}.
At this point, reference is made to Annex 2.
The number is correct, but nameref outputs the wrong name.
\makeatletter
\renewcommand{\section}[1]{%
\par\refstepcounter{section}%
\sectionmark{#1}%
\NR@gettitle{#1}%<---------
\addcontentsline{atoc}{section}{\bfseries\protect\numberline{\thesection}{\mdseries#1}}%
\lohead{\textnormal{#1}}%
}
\makeatother
\section{Second Appendix}
\label{sec:app2}
Appendix 2
\end{document}