ヘッダーのサブセクション

ヘッダーのサブセクション

私は \pagestyle{fancy} を使用しています。ヘッダーとフッターの現在のレイアウトを維持したいと思います (ヘッダーやフッターに何もないページもあれば、アラビア数字のあるページやローマ数字のあるページもあります)。

ヘッダーの左側にセクションまたはサブセクションの名前(サブサブセクションではない)が自動的に表示されるようにしたいと思います。

どうやってやるの?

私のTexファイル:

\documentclass[12pt]{article}
\usepackage[utf8x]{inputenc}

%Header and footer
\usepackage{fancyhdr}
\usepackage{lastpage}
\pagestyle{fancy}

\fancypagestyle{prefacestyle}{
    \fancyhf{} % clear all header and footer fields
    \renewcommand{\headrulewidth}{0pt}
    \lhead{}
    \chead{}
    \rhead{}
    \cfoot{\thepage}
}

\fancypagestyle{documentstyle}{
    \fancyhf{} % clear all header and footer fields
    \renewcommand{\headrulewidth}{0.2pt}
    \lhead{Section or Subsection}
    \chead{}
    \rhead{Name}
    \cfoot{\thepage\ of \pageref{LastPage}}
}

\begin{document}


\thispagestyle{empty}
Frontpage
\newpage
\thispagestyle{empty}
Titlepage


\newpage\pagestyle{prefacestyle}
\pagenumbering{roman}
Preface
\newpage
Abstract
\newpage
Acknowlegdement
\newpage
Contents


\newpage\pagestyle{documentstyle}
\pagenumbering{arabic}
\setcounter{page}{1}

\section{Introduction}
\newpage
\subsection{Related work}
\newpage
\section{Theory}
\newpage
\subsection{method 1}
\newpage
\subsubsection{part 1.1}
\newpage
\subsubsection{part 1.2}
\newpage
\subsection{method 2}
\newpage
\subsubsection{part 2.1}


\end{document}

答え1

他に必要な場合は編集してください。ここを編集してください:

\fancypagestyle{documentstyle}{ \fancyhf{} % すべてのヘッダーとフッターのフィールドをクリア \renewcommand{\headrulewidth}{0.2pt} \lhead{\leftmark} \chead{\rightmark} \rhead{名前} \cfoot{\thepage\ of \pageref{LastPage}} }

関連情報