4

I'm looking to get chapter names in the header of my document. I am using the article class, and the code below is an example of how each chapter/section begins.

\noindent {\huge \textbf {Chapter 1}}
\section{Introduction}

What I'm looking to achieve is a header with the following on the right-hand side:

CHAPTER 1: INTRODUCTION

The header for the pages in chapter two should be:

CHAPTER 2: THEORY

and so on.

Could anyone assist me with this? I know a little about the fancyhdr package, but as I understand, it uses the chapter name in the book class, while I am looking to insert text, and the section name in the article class.

  • For the sake of consistency, I suggest creating a macro to set your chapters, just like \chapter in other document classes that have them. What do you want on the left page header? Do you only have one \section per "chapter"? – Werner Apr 24 '14 at 14:20
  • ...and what about numbering of the sections like what usually happens when you use \section? – Werner Apr 24 '14 at 14:26
  • 1
    Welcome to TeX.SX! Why not using the book class if you have chapters? – egreg Apr 24 '14 at 14:26
  • @Werner I would like the left page header blank. There is only one section, and several subsections per chapter. There is a code snippet that I found lately that suppresses the number beside the Introduction. – Matthew Apr 24 '14 at 14:41
  • 1
    I don't know too much about why you should choose one class over another, but I am using report class. You can have chapters (and I have them in my fancyhdr output. Incidentally, I have just inserted an abstract by just writing "Abstract" and putting some text after it. I don't really understand the point of the abstract environment TBH! – FionaSmith Apr 24 '14 at 15:03
4

In the following minimal example I reformatted \section to be like \chapter by making it a display and inserting Chapter~ before the numbering (all provided by titlesec:

enter image description here

\documentclass[twoside]{article}
\usepackage[a5paper]{geometry}% Just for this example
\usepackage{fancyhdr,titlesec,lipsum}
\pagestyle{fancy}
\fancyhead[L]{}% No header on Left pages

\titleformat{\section}[display]
  {\normalfont\Large\bfseries}{Chapter~\thesection}{1em}{}
\titlespacing*{\section}
  {0pt}{3.5ex plus 1ex minus .2ex}{2.3ex plus .2ex}
\renewcommand{\sectionmark}[1]{\markright{\MakeUppercase{Chapter~\thesection: #1}}{}}

\begin{document}
\section{Introduction}
\lipsum[1-10]
\section{A new section}
\lipsum[1-10]
\end{document}

Effectively \section now looks like \chapter (nothing has been done to affect the way \section* is handled).

1

The titlesec package allows to create new sectioning levels. So I create a chapter level, between part and section, that doesn't start a new page since it is in an article. Of course I have to define its formatting and how it appears in the headers/footers and in the table of contents. All this can be done by titlesec and its companion packagestitlepsandtitletoc`. So here is an attempt:

\documentclass[english, twoside]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{fourier}
\usepackage{microtype}
\usepackage{babel}
\usepackage{lipsum}
\usepackage{chngcntr}

\usepackage[pagestyles, newparttoc, explicit,outermarks]{titlesec}%
\titleformat{\section}[hang]{\large\bfseries\boldmath}{§~\thesection}{0.6em}{\itshape#1}%

\titleclass{\chapter}{straight}[\part]
\newcounter{chapter}
\counterwithin*{section}{chapter}
\renewcommand{\chaptertitlename}{\chaptername}
 \titleformat{\chapter}[block]{\Large\bfseries\boldmath\filleft\lsstyle}{\MakeUppercase{\chaptertitlename}\enspace\thechapter: } {1em} {\MakeUppercase{#1}}%
 \titlespacing{\chapter}{0pt}{2.5\baselineskip}{2\baselineskip}

\makeatletter
 \renewcommand\tableofcontents{%
\chapter*{\contentsname}%
\@starttoc{toc}%
}
\makeatother

\usepackage{titletoc}
\titlecontents{chapter}[1.5em]{\medskip\bfseries}%{1.5em}
{\contentslabel[\MakeUppercase{\romannumeral\thecontentslabel}.]{1.5em}}{}{\hfill\contentspage}[\smallskip]
\titlecontents{section}[2.5em]{}%{1.5em}
{\contentslabel[\thecontentslabel.]{1.2em}}{}{\titlerule*[1pc]{.} \contentspage}

 \newpagestyle{mine}{%
\settitlemarks{chapter, section}%\ifthesection{}
\sethead[][{§\,\thesection.\enspace\itshape\sectiontitle}][]{}{\MakeUppercase{\chaptertitlename~\thechapter.\enspace\chaptertitle}}{}
\setfoot{}{\thepage}{}}%

\pagestyle{mine}

\begin{document}

\tableofcontents
%
\chapter{Introduction}

\lipsum[1-2]
\section{A First Section. }
\lipsum[1-2]%
\section{A Second Section}
\lipsum[1-2]

\chapter{Theory}

\lipsum[1]
\section{Section A}
\lipsum[1]
\section{Section B}
\lipsum[1-8]

\end{document} 

enter image description here

  • There seems to be something wrong with your even headers. – Werner Apr 24 '14 at 18:35
  • @Werner: You're right. I forgot to check all the details. This is due to the fact that in tne article class, the tableofcontents is a \section command. All other even page headers, which I didn't join to my answer, are normal. I'll check for a workaround. – Bernard Apr 24 '14 at 21:13
  • @Werner: Finally it had nothing to do with table of contents (which I turned into a chapter any way), but in the way the marks were set. I changed the default innermarks to outermarksand used the ifthesection test. – Bernard Apr 24 '14 at 23:54
0

If you just a line in the beginning of each chapter redefining you header you should be able to achieve this using fancyhdr. You can read more about using the fancyhdr package here.

The following code should give you what you want.

\documentclass{article}

\usepackage{fancyhdr}

\pagestyle{fancy}
\fancyhead[LE,LO]{}

\renewcommand{\sectionmark}[1]{\markright{\MakeUppercase{#1}}{}}

\begin{document}
\noindent {\huge \textbf {Chapter 1}}
\fancyhead[RE,RO]{CHAPTER 1: \rightmark}
\section{Introduction}
\newpage
\noindent {\huge \textbf {Chapter 2}}
\fancyhead[RE,RO]{CHAPTER 2: \rightmark}
\section{A new section}
\end{document}

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.