
\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
、\section
leftmark と\subsection
rightmark を設定します。
したがって、このデフォルトの動作を変更するか、 を使用する必要があります\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}