本地和全局交叉引用

本地和全局交叉引用

许多不同的地方都引用了这些章节:

在目录中。由 \tableofcontents 管理 在 minitocs 中。由 minitoc 包管理 在标题中。由 fancyhdr 包管理 像引导部分一样。由 \section 管理 在文本中。由 \ref 管理 在 tocs 和 minitocs 中,由于每个部分都出现在其章节下方(带有一些缩进),因此无需在部分编号前加上章节编号。标签范围是本地的;所以我需要本地渲染。示例:

              1. Chapter One ------------------1
                   1. First section -----------1
                   2. Second section ----------3
               2. Chapter Two -----------------5
                   1. First section ...........5

这意味着第 1.1 节和第 2.1 节必须呈现为第 1 节。

当我们使用 \section 命令时,我们知道我们在哪一章:它显示在页面的标题中。所以我还想要本地范围:

         1. First section
                    bla bla
         2. Second section
                   bla bla

在标题中我想要全局范围:

         1. Chapter One                      1.1. First section

在文本中,我们可以对文本的任意点进行交叉引用。所以我们需要全局范围:

            See section 1.1 (first section in first chapter)

这就是问题所在:默认行为在任何地方都赋予全局范围。但如果我重新定义\thesection为本地范围,那么我就会在所有地方重新定义。

这是我的代码:

\documentclass[catalan]{book}
\usepackage{fancyhdr}
\usepackage{nameref}
\usepackage{minitoc}
\usepackage{hyperref}

\makeindex
\dominitoc

%\renewcommand{\thesection}{\arabic{section}}

\renewcommand{\chaptermark}[1]{\markboth{\thechapter\ #1}{}} \renewcommand{\sectionmark}[1]{\markboth{\thechapter.\thesection\ \ #1}}

\fancyhead{}
\fancyhead[LO]{\leftmark}
\fancyhead[RE]{\thechapter.\rightmark}

\pagestyle{fancy}

\begin{document} \tableofcontents \chapter{One}

\minitoc[e]

\section{First section}
\label{sec:A}
aaaaaa \newpage bbbbbbbb \newpage
ccccccccccc

\chapter{Two} \minitoc[e]
\section{Second section}
\label{sec:B}

See sections \ref{sec:A} and \ref{sec:B}

\end{document}

答案1

用来\renewcommand{\thesection}{\arabic{section}}正确获取章节标题旁边的数字。否则更改会很困难。

用于\renewcommand{\sectionmark}[1]{\markright{\thechapter.\thesection\ #1}}标题。

对于参考文献,您可以使用例如 zref 来设置“fullsec”参考文献。但我觉得这很令人困惑。如果您有 2.1 小节怎么办?我也会在章节后面放置一个 \label,然后写一些类似于参见第 2 章中的第 1 节的内容。

答案2

最初我发布了一个令人困惑的问题,我如何才能获得像所有参考文献的前缀一样的章节编号。这个问题就是这个问题的起源。

TH 发布的答案。这是对当前问题的很好的答案

相关内容