0

When using the book document class one gets the chapter nr. and section name in the header. However, I've found no way of doing this in the report class. Looking at the fancyhdr package it seems like one must enter the name of the section and chapter nr. for each new section, and it not changing if one should (only) change the name in \section{} command, as it does in the book format. Is there a way to achieve this in some package?

EDIT: Was asked to give some code as to show what I've attempted When using the "book class", and utlizing this code you will find that on page 6 it says "Chapter 1: Test" in the upper right corner.

\documentclass{book}
\author{Me}
\title{Test Document}
\begin{document}
\maketitle
\tableofcontents
\newpage
 Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis eget dui vitae 
 risus sollicitudin consequat eu ultricies nibh. Proin rhoncus eros in dictum 
 laoreet. Vestibulum quis velit vitae nibh interdum pretium. Cras ac molestie 
 massa, ac venenatis metus. Class aptent taciti sociosqu ad litora torquent 
 per conubia nostra, per inceptos himenaeos. Etiam porttitor, quam at dictum  
ursus, ipsum erat condimentum elit, id volutpat tellus lacus eget magna. 
Phasellus et viverra lectus. Cras lacus massa, tincidunt sit amet dignissim 
vel, sollicitudin a leo. Donec efficitur eleifend laoreet. Suspendisse vitae   
nisi congue, pretium est sit amet, rutrum nibh.
\chapter{Test}

Phasellus efficitur arcu sit amet nisl varius interdum. Nulla aliquet ex id 
orci maximus, sit amet malesuada orci rhoncus. Sed tempus elit a dui 
venenatis 
lobortis. Aenean eget consectetur urna. Donec tincidunt sapien nec nibh 
egestas porttitor. Nam ultricies, velit sit amet blandit sollicitudin, mauris 
est fringilla tellus, id condimentum nunc libero vitae velit. Morbi venenatis 
dui at dui sodales malesuada.
\newpage
\section{Test1} 
Aliquam pretium in nisi eget sodales. Nulla congue, quam vel euismod 
lobortis, 
tortor arcu blandit tellus, a consequat enim mi at elit. Aenean ultricies, 
velit quis tempus varius, metus turpis finibus odio, aliquet posuere nulla 
ligula in metus. Etiam a bibendum sem. Suspendisse dictum rhoncus quam vel   
fermentum. Fusce in accumsan sapien, in cursus nibh. Integer cursus arcu 
eleifend urna rhoncus pharetra. Nulla at ultricies ipsum. Aliquam non nibh 
varius nibh bibendum auctor ut id nisi. Fusce lacinia, justo vitae efficitur 
sagittis, velit dolor pellentesque enim, eget porttitor velit diam a velit. 
Nullam tincidunt est leo, sed suscipit dui venenatis in. Praesent a auctor 
neque, sed faucibus dolor. Suspendisse ante tellus, p  retium ut diam eget, 
euismod convallis mauris. Cras semper viverra turpis. Nulla pharetra 
fringilla 
lorem, et suscipit ante faucibus non.
\end{document}

Should one however change the class to \documentclass{report} no such header would be prodused. As I understand from the documentation for the fancyhdr package (which is the only thing I've found to create something similar by googling) it seems like I would have to manualy set what each sections header should be, rather than this been automaticly the name of the section.

2
  • Welcome to TeX SX! Could you post some compilable code of what you tried?
    – Bernard
    Nov 18, 2020 at 14:13
  • Hi, there! No problem, I've added some code now as an attempt at making it more clear. Nov 18, 2020 at 15:30

1 Answer 1

0

As you have already discovered, fancyhdr will help you with the job.

I include a sample of a longer document to see how it works (kantlipsum is just for adding dummy text).

You can play with right (R), left (L), or middle (C) headers or footers.

If you read the manual, you will see many examples, including choosing different headings for odd or even pages.

Typically you will use a minimum of 3 styles in a document, empty (no headers and footers, for a cover), plain (only page numbers, for table of contents or special pages), and fancy (the rest).

\documentclass{report}

\usepackage{kantlipsum} % just for dummy text   
\usepackage{fancyhdr} % 

\fancypagestyle{mystyle}{%
\fancyhf{} % clear all headers      
\fancyhead[R]{\rmfamily \small \nouppercase \rightmark}
\fancyhead[L]{\rmfamily \small \nouppercase \leftmark}  
\fancyfoot[C]{\thepage}
\renewcommand{\headrulewidth}{0pt}
\renewcommand{\footrulewidth}{0pt}}

\fancypagestyle{plain}{%
\fancyhf{} % clear all header and footer fields
\fancyfoot[C]{\textbf{\thepage}} % except the center
\renewcommand{\headrulewidth}{0pt}
\renewcommand{\footrulewidth}{0pt}}

\author{Me}
\title{Test Document}

\begin{document}    
\maketitle
\pagestyle{plain}
\tableofcontents
\newpage    
\textbf{\Large Acknowledgments} 

\kant[2]    

\chapter{Test Ch One}
\pagestyle{mystyle}
\kant[1-8]  
\newpage
\section{Section 1-One}     
\kant[9-12] 
\section{Section 1-Two}     
\kant[9-12] 
\chapter{Test Ch Two}   
\kant[1-8]  
\newpage
\section{Section 2-One}     
\kant[9-12] 
\section{Section 2-Two}     
\kant[9-12] 

\end{document}

p1

p2

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .