
何時間もこれをやろうとしていますが、うまくいきません。
ドキュメントの左側のヘッダーを、番号なしの章の名前として表示したいです。右側のヘッダー (問題の原因) は、セクション番号 + セクション名になります。
例えば:
はじめに 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}