1

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}
3
  • Welcome to TeX.SX! Why don't you use and customize arsclassica then?
    – TeXnician
    Jun 16 '17 at 8:12
  • Thanks. As I mentioned, some things don't work with arsclassica. footnote back/cross reference, font customization(That's almost done) And I think it's a good way to learn latex.
    – Heath Kim
    Jun 16 '17 at 8:16
  • That's what I meant with customize it.
    – TeXnician
    Jun 16 '17 at 8:17
1

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}
2
  • Thanks! But I want one more thing with your answer. I don't want section numbering on the header. Please help one more time.
    – Heath Kim
    Jun 16 '17 at 8:20
  • @HeathLucasKim Use \renewcommand{\sectionmark}[1]{\markboth{#1}{#1}} after loading fancyhdr.
    – TeXnician
    Jun 16 '17 at 8:28
2

The code is much simpler with titleps:

\documentclass[12pt,a4paper,twoside]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[dvipsnames,svgnames,table]{xcolor}

%************************************************************
% Headlines
%************************************************************
\usepackage{titleps}
\newpagestyle{classica}{%
\sethead{}{}{\sectiontitle\quad|\quad\thepage}
}

\usepackage{blindtext}
\usepackage{parskip}
\pagestyle{classica}

\begin{document}

   \blinddocument

\end{document} 

enter image description here

2
  • You're welcome! B.t.w. you don't have to load color if you load xcolor (it's automatic) and the usenames option for xcolor has been deprecated for quite a few years, as it's the default now.
    – Bernard
    Jun 16 '17 at 8:40
  • good to know that! eww, latex is hard to learn but that's why I attracted to.
    – Heath Kim
    Jun 16 '17 at 8:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.