サブセクションなしの rightmark ですか?

サブセクションなしの rightmark ですか?

\documentclass{article}と を使用して、\pagestyle{fancy}ヘッダーのみを表示し\section、 を表示しないように定義する方法を知っている人はいますか\subsection?

ファンシーは以下のように定義しました。

\fancyhead{}
\fancyhead[LO, LE]{\small\emph{My book}}
\fancyhead[RO, RE]{\small\rightmark}
\fancyfoot[CO, CE]{}
\fancyfoot[RO, RE]{\thepage}

そして私は定義しました\sectionmark

\renewcommand{\sectionmark}[1]{\markboth{}{\emph{\thesection \#1}}}

\subsectionヘッダーのみだったのでテキストでどのページが使われているかは分かりません\section

答え1

いくつかの点:

  • 機能も削除する必要があり\subsectionmarkます。
  • 使用は\#1誤りです。文字通り、#1ヘッダーに印刷することを意味します。

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

\documentclass[twoside]{article}

\usepackage{fancyhdr,lipsum}

\pagestyle{fancy}
\fancyhead{}
\fancyhead[LO, LE]{\small\emph{My book}}
\fancyhead[RO, RE]{\small\rightmark}
\fancyfoot[CO, CE]{}
\fancyfoot[RO, RE]{\thepage}
\renewcommand{\sectionmark}[1]{\markboth{}{\emph{\thesection~#1}}}
\renewcommand{\subsectionmark}[1]{}% Remove \subsection from header

\begin{document}

\section{A section}
\lipsum[1]
\subsection{A subsection}
\lipsum[2]
\subsubsection{A subsubsection}
\lipsum[3]

\section{A section}
\lipsum[1]
\subsection{A subsection}
\lipsum[2]
\subsubsection{A subsubsection}
\lipsum[3]

\end{document}

答え2

articleオプション付きのクラスではtwoside\sectionleftmark と\subsectionrightmark を設定します。

したがって、このデフォルトの動作を変更するか、 を使用する必要があります\leftmark。ただし、この場合、ヘッダーは特定のページで始まるセクションを反映します。どのような動作を好むかはあなた次第です。

入力は以下のように簡略化することもできます。 のような書式指定は、またはではなく、\emphに属します。\fancyhead\fancyfoot\markboth\markright

設定は のままにしました\leftmark。コメントを に切り替えて を使用します\rightmark

\documentclass[twoside]{article}

\usepackage{fancyhdr,lipsum}

\pagestyle{fancy}
\fancyhf{} % clear all fields
\fancyhead[L]{\small\emph{My book}}
% first possibility: use the leftmark
\fancyhead[R]{\small\emph{\leftmark}}
% second possibility: use the rightmark
%\fancyhead[R]{\small\emph{\leftmark}}
\fancyfoot[R]{\thepage}

% first possibility: use the leftmark
\renewcommand{\sectionmark}[1]{\markboth{\thesection~#1}{}}

% second possibility: use the rightmark
%\renewcommand{\sectionmark}[1]{\markright{\thesection~#1}}
%\renewcommand{\subsectionmark}[1]{}

\begin{document}

\section{A section}
\lipsum[1]
\subsection{A subsection}
\lipsum[2]
\subsubsection{A subsubsection}
\lipsum[3]

\section{A section}
\lipsum[1]
\subsection{A subsection}
\lipsum[2]
\subsubsection{A subsubsection}
\lipsum[3]

\end{document}

関連情報