在 fancyhdr 中取得不帶章節號的節標記

在 fancyhdr 中取得不帶章節號的節標記

我已經嘗試完成這件事幾個小時了,但我無法讓它發揮作用。

我希望文件中的左側標題顯示為章節名稱,沒有數字。正確的(引起麻煩的)是節號+節名。

例如:

引言 4. 行星形成

這就是我到目前為止所擁有的

\renewcommand{\chaptername}{}
\renewcommand{\chaptermark}[1]{\uppercase{\markboth{#1}{}}}
\renewcommand{\sectionmark}[1]{\markright{#1}{}}

我正在使用以下命令來列印標題

\lhead[\thepage]{\leftmark} 
\rhead[\nouppercase{\rightmark}]{\thepage}

但輸出是簡介 1.4。行星形成

你能給我一些幫助嗎?

答案1

使用

\renewcommand{\chaptermark}[1]{\markboth{#1}{}}

您將在左側標記中獲得章節標題,然後使用

\renewcommand{\sectionmark}[1]{\markright{\arabic{section}.\ #1}}

您將獲得右標記的節號(不含章節號前綴)和標題。

一個完整的例子:

\documentclass{book}
\usepackage[a6paper]{geometry}
\usepackage{fancyhdr}
\usepackage{lipsum}
\pagestyle{fancy}

\renewcommand{\chaptermark}[1]{\markboth{#1}{}}
\renewcommand{\sectionmark}[1]{\markright{\arabic{section}.\ #1}}

\lhead[\thepage]{\leftmark} 
\rhead[\nouppercase{\rightmark}]{\thepage}

\begin{document}

\chapter{Test chapter}
\section{Test section}
\lipsum[1-4]

\end{document}

結果:

在此輸入影像描述

您的 \lhead、\rhead 命令可以替換為“更現代的”

\fancyhead[EL,OR]{\thepage}
\fancyhead[ER]{\rightmark}
\fancyhead[OL]{\leftmark} 

相關內容