[Tex/LaTex] How to make right top header in `article` document class

header-footer

How to make the right top header in article document class?

I want to make arsclassica style right top header(section name | page number) without massively styled packages or document classes.

I can put vertical bar and page number using by fancyhdr package but
I can't find a way to add section name or subsection name to the header.

I'm making a template for own use from scratch, without classicthesis, arsclassica packages because some things don't work with those packages.
(e.g. footnote back(cross) reference, font things)

I'm trying to copy arsclassica style.
Sadly, it's harder than I expected.

MWE is here.

\documentclass[12pt,a4paper,twoside]{article}

\usepackage{color}
\usepackage[usenames,dvipsnames,svgnames,table]{xcolor}

%************************************************************
% Headlines
%************************************************************
\usepackage{fancyhdr}
\pagestyle{fancy}

\pagestyle{fancy}
\fancyhf{}
\fancyheadoffset{0cm}
\renewcommand{\headrulewidth}{0pt} 
\renewcommand{\footrulewidth}{0pt}
\fancyhead[R]{
  \color{lightgray}{\thesection}
  }
\fancyhead[R]{
  \color{lightgray}{\vline}\hspace{1em}\color{gray}\thepage
  }
\fancypagestyle{plain}{%
  \fancyhf{}%
  \fancyhead[R]{\thepage}%
  }


\usepackage{blindtext}
\usepackage{parskip}

\begin{document}
   \blinddocument
\end{document}

Best Answer

You could simply use \leftmark which should do the job for you.

leftmark

\documentclass[12pt,a4paper,twoside]{article}

\usepackage{color}
\usepackage[usenames,dvipsnames,svgnames,table]{xcolor}

%************************************************************
% Headlines
%************************************************************
\usepackage{fancyhdr}
\pagestyle{fancy}

\pagestyle{fancy}
\fancyhf{}
\fancyheadoffset{0cm}
\renewcommand{\headrulewidth}{0pt} 
\renewcommand{\footrulewidth}{0pt}
\fancyhead[R]{
  \color{lightgray}{\thesection}
  }
\fancyhead[R]{
 \color{gray} \leftmark~\color{lightgray}{\vline}\hspace{1em}\color{gray}\thepage
  }
\fancypagestyle{plain}{%
  \fancyhf{}%
  \fancyhead[R]{\thepage}%
  }


\usepackage{blindtext}
\usepackage{parskip}

\begin{document}
   \blinddocument
\end{document}
Related Question