\markboth が機能しないのはなぜですか?

\markboth が機能しないのはなぜですか?

執筆中の本に独自の見出しを付けようとしています。「左」と「右」という 2 つの見出しを交互に表示したいのですが、問題は、 を使用すると左と右が印刷されないことです\markboth

コードは

\documentclass{book}

\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{graphicx}
\usepackage{graphics,color}
\usepackage[superscript]{cite}

\begin{document}
\pagestyle{myheadings}
\markboth{Right}{Left}

First page
\newpage
Second page
\newpage
Third page
\newpage
Fourth page

 \end{document}

これにより、次のことが実現されます。
ここに画像の説明を入力してください

2ページ目:
ここに画像の説明を入力してください

しかし、私は次のようになりたいです(以下):
ここに画像の説明を入力してください

2ページ目:
ここに画像の説明を入力してください

3番目:
ここに画像の説明を入力してください

4番目:
ここに画像の説明を入力してください

答え1

あなたが投稿した希望の出力画像には、ヘッダーの下に罫線が引かれ、余白が縮小されています。余白を設定するには、geometryパッケージを使用するのが最適です。ヘッダーについては、パッケージが必要な機能を提供します。あなたの構文 (実際には逆にfancyhdrなっていますが) を使用すると、次のように記述できます。RightLeft

サンプルページ2

\documentclass[a4paper,12pt]{book}

\usepackage[vmargin=0.2cm,hmargin=1cm,head=16pt,includeheadfoot]{geometry}
\usepackage{fancyhdr}
\fancyhead{}
\fancyfoot{}
\fancyhead[LE,RO]{\thepage}
\fancyhead[LO]{\slshape\rightmark}
\fancyhead[RE]{\slshape\leftmark}
\pagestyle{fancy}

\begin{document}

\markboth{Right}{Left}
\thispagestyle{empty}

First page
\newpage
Second page
\newpage
Third page
\newpage
Fourth page

\end{document}

\pagestyle{empty}最初のページ (またはコマンドが実行されるページ) にヘッダーがないことを確認します。

\markboth標準的な方法を使用するには、次のようにします。

\documentclass[a4paper,12pt]{book}

\usepackage[vmargin=0.2cm,hmargin=1cm,head=16pt,includeheadfoot]{geometry}
\usepackage{fancyhdr}
\fancyhead{}
\fancyfoot{}
\fancyhead[LE,RO]{\thepage}
\fancyhead[LO]{\slshape\leftmark}
\fancyhead[RE]{\slshape\rightmark}
\pagestyle{fancy}

\begin{document}

\markboth{Left}{Right}
\thispagestyle{empty}

First page
\newpage
Second page
\newpage
Third page
\newpage
Fourth page

\end{document}

関連情報