沒有小節的右標?

沒有小節的右標?

有誰知道如何使用\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設定左標記和\subsection右標記。

因此,您需要更改此預設行為或僅使用\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}

相關內容