我正在写一篇长篇文章,它分为几个部分、多个章节等。在文档的后面部分,我需要引用属于前一部分的章节等,比如在文档的第二部分,我需要引用第一部分的第 1 节。
但是,\autoref{}
仅创建名为“第 1 节”而不是第 I 部分第 1 节的链接。换句话说,仍然不清楚引用的部分属于哪个部分。
有没有什么方法可以创建显示部分、章节、节等完整层次结构的参考资料?
非常感谢您的支持!
此致
NP。
\documentclass[12pt, a4paper, tocindentauto]{scrbook}
\usepackage{hyperref}
\begin{document}
\part{Part 1}
\chapter{Chapter 1}
\label{chap:P1chap1}
\section{Section 1}
\label{sec:P1chap1section1}
\subsection{Subsection 1}
\label{ssec:sec:P1chap1section1subsection1}
\part{Part 2}
\chapter{Chapter 1}
\label{chap:P2chap1}
\autoref{chap:P1chap1} should look like: I.1
\autoref{sec:P1chap1section1} should look like I.1.1
\autoref{ssec:sec:P1chap1section1subsection1} should look like I.1.1.1
\autoref{chap:P2chap1} should look like II.1
\end{document}
感谢大家迄今为止的支持!然而,事情变得更加复杂了... :-/ 虽然示例中的引用工作正常,但我的“真实”文档使用了一些自定义的目录编号。不幸的是,这些命令似乎会干扰\ref{}
命令。
以下是更新后的代码,包括目录和自定义编号:
\documentclass[12pt, a4paper, tocindentauto]{scrbook}
\renewcommand\thepart{\Alph{part}}
\renewcommand\thechapter{\Roman{chapter}}
% ISSUE SEEMS TO BE RELATED TO THESE IN CONJUNCTION WITH TABLE OF CONTENTS
\renewcommand\thesection{\arabic{section}}
\renewcommand\thesubsection{\thesection.\arabic{subsection}}
\usepackage{chngcntr}
\counterwithin*{chapter}{part}
\usepackage{hyperref}
\makeatletter
\AtBeginDocument{%
\def\@prependpart\csname #1\endcsname{%
\thepart.\csname#1\endcsname%
}
\renewcommand{\p@chapter}{\@prependpart}
\renewcommand{\p@section}{\@prependpart}
\renewcommand{\p@subsection}{\@prependpart}
\renewcommand{\p@subsubsection}{\@prependpart}
\let\theHchapterorig\theHchapter%
\renewcommand{\theHchapter}{\thepart.\theHchapterorig}
}
\makeatother
\setcounter{secnumdepth}{3}
\begin{document}
\tableofcontents
\part{Title Part A}
\chapter{Chapter 1}
\label{chap:P1chap1}
\section{Section 1}
\label{sec:P1chap1section1}
\section{Section 2}
\label{sec:P1chap1section2}
\subsection{Subsection 1}
\label{ssec:sec:P1chap1section1subsection1}
\subsubsection{Subsubsection 1}
\label{ssec:sec:P1chap1section1subsubsection1}
\subsubsection{Subsubsection 2}
\label{ssec:sec:P1chap1section1subsubsection2}
\part{Title Part B}
\chapter{Chapter 1}
\label{chap:P2chap1}
\ref{chap:P1chap1} should look like: A.I - OK
\ref{sec:P1chap1section1} should look like A.I.1 - I missing
\ref{ssec:sec:P1chap1section1subsubsection2} should look like A.I.2.1.2 - I missing
\ref{chap:P2chap1} should look like B.I - OK
\end{document}
答案1
只是\counterwithin{chapter}{part}
在所有被调用的地方都加上零件编号\thechapter
,因此在目录和章节标题中以及每个\thesection
等等中。
据我了解,只有参考文献应该改变,因此在被引用时Part 3, Chapter 5
应该改变。III.5
这需要通过使用“参数”抓取器来重新定义\p@chapter
和等命令,比如将输出添加到参考并在定义时存储在文件中,即冻结了参考的正确零件编号。\p@section
\@prependpart
\thepart.
.aux
除了被放入chapter
的重置列表之外part
,这还会导致 的超级锚点系统出现问题hyperref
。第一章的超级锚点通常被称为chapter.1
,但重置每个部分的章节编号后,chapter.1
锚点不再是唯一的。
重新定义\theHchapter
锚宏将解决这个问题。
\documentclass[12pt, a4paper, tocindentauto]{scrbook}
\usepackage{chngcntr}
\counterwithin*{chapter}{part}
\usepackage{hyperref}
\makeatletter
\AtBeginDocument{%
\def\@prependpart\csname #1\endcsname{%
\thepart.\csname#1\endcsname%
}
\renewcommand{\p@chapter}{\@prependpart}
\renewcommand{\p@section}{\@prependpart}
\renewcommand{\p@subsection}{\@prependpart}
\renewcommand{\p@subsubsection}{\@prependpart}
\let\theHchapterorig\theHchapter%
\renewcommand{\theHchapter}{\thepart.\theHchapterorig}
}
\makeatother
\begin{document}
\part{Part 1}
\chapter{Chapter 1}
\label{chap:P1chap1}
\section{Section 1}
\label{sec:P1chap1section1}
\subsection{Subsection 1}
\label{ssec:sec:P1chap1section1subsection1}
\part{Part 2}
\chapter{Chapter 1}
\label{chap:P2chap1}
\autoref{chap:P1chap1} should look like: I.1
\autoref{sec:P1chap1section1} should look like I.1.1
\autoref{ssec:sec:P1chap1section1subsection1} should look like I.1.1.1
\autoref{chap:P2chap1} should look like II.1
\end{document}
更新其他编号方案
\documentclass[12pt, a4paper, tocindentauto]{scrbook}
\renewcommand\thepart{\Alph{part}}
\renewcommand\thechapter{\Roman{chapter}}
% ISSUE SEEMS TO BE RELATED TO THESE IN CONJUNCTION WITH TABLE OF CONTENTS
\renewcommand\thesection{\arabic{section}}
\renewcommand\thesubsection{\thesection.\arabic{subsection}}
\usepackage{chngcntr}
\counterwithin*{chapter}{part}
\usepackage{xpatch}
\usepackage{hyperref}
\makeatletter
\AtBeginDocument{%
\xpretocmd{\p@chapter}{\thepart.}{}{}
\xpretocmd{\p@section}{\thepart.\thechapter.}{}{}
\xpretocmd{\p@subsection}{\p@section}{}{}
\xpretocmd{\p@subsubsection}{\p@subsection}{}{}
\@ifpackageloaded{hyperref}{%
\let\theHchapterorig\theHchapter%
\renewcommand{\theHchapter}{\thepart.\theHchapterorig}%
}{}
}
\makeatother
\setcounter{secnumdepth}{3}
\begin{document}
\tableofcontents
\part{Title Part A}
\chapter{Chapter 1}
\label{chap:P1chap1}
\section{Section 1}
\label{sec:P1chap1section1}
\section{Section 2}
\label{sec:P1chap1section2}
\subsection{Subsection 1}
\label{ssec:sec:P1chap1section1subsection1}
\subsubsection{Subsubsection 1}
\label{ssec:sec:P1chap1section1subsubsection1}
\subsubsection{Subsubsection 2}
\label{ssec:sec:P1chap1section1subsubsection2}
\part{Title Part B}
\chapter{Chapter 1}
\label{chap:P2chap1}
\ref{chap:P1chap1} should look like: A.I - OK
\ref{sec:P1chap1section1} should look like A.I.1 - I missing
\ref{ssec:sec:P1chap1section1subsubsection2} should look like A.I.2.1.2 - I missing
\ref{chap:P2chap1} should look like B.I - OK
\end{document}