
我正在使用這個代碼
\pagestyle{fancy}
\fancyhf{}
\renewcommand{\headrulewidth}{0.5pt}
\renewcommand{\footrulewidth}{0.5pt}
\lhead{\textit{\leftmark}}
\rhead{\textit{\rightmark}}
\rfoot{\textit{Page \thepage}}
\renewcommand{\sectionmark}[1]{\xdef\leftmark{\thesection\quad#1}\xdef\rightmark{}}
\renewcommand{\subsectionmark}[1]{\xdef\rightmark{\thesubsection\quad#1}}
列印標題中的小節標題。但是,我有一個問題,如果該小節列印在頁面頂部,那麼它會顯示在上一頁的標題中。如下圖所示。
這是第 1.1 節,但標題顯示第 1.2 節。我該如何解決?我目前的解決方案是執行以下操作。
\begin{Def}
Let $\{M_i:i \in \{1,\ldots ,k\} \}$ be a family of submodules of an $R$-module $M$. Then $M$ is the \textit{direct sum} of $M_1,\ldots ,M_k$ if\\
\indent i) $M=M_1\oplus \ldots \oplus M_k\coloneqq \{ m_1+\ldots +m_k: m_i \in M_i\}$; \\
\indent ii) $M_i \cap M_j = \emptyset $ for all $i \neq j$.
\end{Def}
\newpage
因此,我只需\newpage
在頁面末尾添加一條命令即可解決問題。
答案1
在您的程式碼中,將 和 替換\xdef\leftmark
為\markboth
和\xdef\rightmark
by \markright
,以便重新定義\sectionmark
和的兩行將\subsectionmark
如下所示:
\renewcommand{\sectionmark}[1]{\markboth{\thesection\quad#1}{}}
\renewcommand{\subsectionmark}[1]{\markright{\thesubsection\quad#1}}