[Tex/LaTex] fancyhdr – Only show sections, not subsections

fancyhdrheader-footer

Is there a way for the header to only print the title of the parent section? So in the example below, the subsection{LOL} page will have "1.1 LOL" written in the header. I just want it to say "Introduction" which is the parent section.

\documentclass[a4paper,12pt]{scrartcl}

\usepackage{fancyhdr}

\begin{document}
\pagestyle{fancy}
\renewcommand{\sectionmark}[1]{\markright{#1}}

\fancyhf{}

\rhead{\fancyplain{}{MyName}} % predefined ()
\lhead{\fancyplain{}{\rightmark }} % 1. sectionname
\cfoot{\fancyplain{}{\thepage}}

\section{Introduction}
\newpage
\subsection{LOL}

\end{document}

Best Answer

Either you also redefine \subsectionmark or use the \leftmark; in article type classes, \subsection emits a \markright command.

\documentclass[a4paper,12pt]{scrartcl}

\usepackage{fancyhdr}

\pagestyle{fancy}
\renewcommand{\sectionmark}[1]{\markboth{#1}{}} % set the \leftmark

\fancyhf{}
\fancyhead[R]{MyName} % predefined ()
\fancyhead[L]{\leftmark} % 1. sectionname
\fancyfoot[C]{\thepage}
\fancypagestyle{plain}{%
  \fancyhf{}%
  \renewcommand{\headrulewidth}{0pt}%
}

\begin{document}
\section{Introduction}
\newpage
\subsection{LOL}

\end{document}

enter image description here

Note also the "modern" fancyhdr syntax that avoids \fancyplain.