0

This is what I have ("Integrales" is just a title, means "Integrals")

enter image description here

where "Integrals" is a section title and "Analytics Functions Theorems" a subsection title. What I need is the section AND subsection title in the header. That is:

enter image description here

Please ignore the color of the header, that is not needed. Some of my code is this:

\documentclass[11pt, oneside]{book}

\usepackage{fancyhdr}  
    \pagestyle{fancy}
    \fancyhf{}

    \renewcommand{\chaptermark}[1]{\markboth{#1}{#1}}
    \renewcommand{\sectionmark}[1]{\markright{#1}}
    

\fancyhead[C]{\ttfamily\nouppercase{\rightmark}}


\begin{document}
     \section{Integrals}
     \subsection{Analytics Functions Theorems}


\end{document}

1 Answer 1

1

You question is quite unclear, because with book or report the topmost heading level would be \chapter not \section. And because oneside with book is also strange, here a suggestion with report, \chapter and \section:

\documentclass[11pt,oneside]{report}

\usepackage{fancyhdr}  
\pagestyle{fancy}
\fancyhf{}

\renewcommand{\chaptermark}[1]{\markboth{#1}{#1}}
\renewcommand{\sectionmark}[1]{\markright{#1}}
    

\fancyhead[R]{\ttfamily\nouppercase{\leftmark\quad\rightmark}}

\usepackage{mwe}

\begin{document}
\chapter{Integrals}
\section{Analytics Functions Theorems}
\lipsum

\end{document}

example with report, chapter, section and fancyhdr

If you want the page header also on pages with \chapter you need to additionally redefine page style plain (see section 11 of the fancyhdr manual). However, this would not give you the section title on the chapter page, because the second element of \markboth{#1}{#1} would be preferred over \markright.

With scrlayer-scrpage instead if fancyhdr you could use:

\documentclass[11pt]{report}
%\documentclass[11pt,oneside]{book}% also possible

\usepackage[autooneside=false,markcase=used,automark]{scrlayer-scrpage}
\ihead[]{}
\setkomafont{pageheadfoot}{}
\setkomafont{pagehead}{\ttfamily}
\ohead*{\rightmark: \leftbotmark}

\renewcommand{\chaptermark}[1]{\markright{#1}}
\renewcommand{\sectionmark}[1]{\markleft{#1}}

\usepackage{mwe}

\begin{document}
\chapter{Integrals}
\section{Analytics Functions Theorems}
\lipsum

\end{document}

result with report, chapter, section and scrlayer-scrpage

However, this could result in wrong headings, if chapter page does not have a section. But such an issue could be fixed using an explicit \markleft{} after the \chapter{…} command.

You can do similar with article instead of report (or book) and using \section or \subsection. Here you don't need to redefine the plain page style:

\documentclass[11pt]{article}

\usepackage[autooneside=false,markcase=used,automark]{scrlayer-scrpage}
\ihead[]{}
\setkomafont{pageheadfoot}{}
\setkomafont{pagehead}{\ttfamily}
\ohead{\rightmark: \leftbotmark}

\renewcommand{\sectionmark}[1]{\markright{#1}}
\renewcommand{\subsectionmark}[1]{\markleft{#1}}

\usepackage{mwe}

\begin{document}
\section{Integrals}
\subsection{Analytics Functions Theorems}
\lipsum

\end{document}

result with article, section, subsection and scrlayer-scrpage

And surely you could do this also using book, but IMHO it wouldn't make much sense, and you would have to decide, what to do with chapter pages:

\documentclass[11pt,oneside]{book}

\usepackage[autooneside=false,markcase=used]{scrlayer-scrpage}
\automark{section}
\ihead[]{}
\setkomafont{pageheadfoot}{}
\setkomafont{pagehead}{\ttfamily}
\ohead{\rightmark: \leftbotmark}% \ohead*{…} instead of \ohead{…} for page header on the chapter pages

\renewcommand{\sectionmark}[1]{\markright{#1}}
\renewcommand{\subsectionmark}[1]{\markleft{#1}}

\usepackage{mwe}

\begin{document}
\chapter{What to do with this page?}
\section{Integrals}
\subsection{Analytics Functions Theorems}
\lipsum

\end{document}

result with book, section, subsection and scrlayer-scrpage

Note: If you would like to have a line below the page header, scrlayer-scrpage provides options headsepline and plainheadsepline. And if you want to move the page number from the bottom also to the head, you have to use, e.g.,

\clearpairofpagestyles
\ohead*{\rightmark: \leftbotmark\quad\pagemark}

See chapter 5 of the KOMA-Script manual (either in English or German) for more information.

I'm almost sure, similar could be done using fancyhdr, but I'm always using scrlayer-scrpage, so I know it better.

1
  • That's exactly what I needed. Thank you! (and sorry for being unclear, i'm still learning how to ask)
    – Peluche
    Nov 18, 2022 at 14:41

You must log in to answer this question.

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