Page Layouthow can I create headers configured with fancyhdr

Information and discussion about page layout specific issues (e.g. header and footer lines, page formats, page numbers).
Post Reply
royer11
Posts: 7
Joined: Tue Jul 23, 2019 12:20 am

how can I create headers configured with fancyhdr

Post by royer11 »

I have configured my header in the following way
Image

As you can see, in the red rectangle I want to add the section title but I have become confused and I cannot achieve it:

packages:

Code: Select all

\documentclass[14pt]{extbook}
\usepackage[pass,paperwidth=8.5in,paperheight=11in]{geometry}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{xcolor}
\usepackage{lipsum}
\usepackage{fancyhdr}
configure fancyhdr

Code: Select all

\fancyhf{}
\fancyhead[LE,RO]{{\ooalign{%
\color{black!70!white}% background box color
\rule[0.04in]{0.8in}{0.9in}% background box raise, width, height
\cr
\hfil\strut\raisebox{0.25in}{% number raise
\fontfamily{ugq}\selectfont\bfseries\color{white}% number color
\large% number fontsize
\thepage
\kern0.1em% distance number-bar
\kern0.15em% distance bar-totalnumber
\small% totalnumber fontsize
}\hfil
}}}
\fancyheadoffset[LE,RO]{1.2in}% protrusion 
\pagestyle{fancy}
\renewcommand{\headrulewidth}{2pt}
\renewcommand{\footrulewidth}{1pt}
and body

Code: Select all

\begin{document}
\chapter{Title}
\section{Title 1}
\begin{quote}
    \lipsum
\end{quote}
\section{Title 2}
\begin{quote}
    \lipsum
\end{quote}
\end{document}
reference style
https://tex.stackexchange.com/questions ... r-fancyhdr

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

User avatar
Ijon Tichy
Posts: 640
Joined: Mon Dec 24, 2018 10:12 am

how can I create headers configured with fancyhdr

Post by Ijon Tichy »

You just have to add \leftmark and/or \rightmark somewhere in your pagestyle definition. However, you also have to change the page geometry, otherwise there is not enough room for such a large head (see the warning of fancyhdr).

Example:
\documentclass[14pt]{extbook}
\usepackage[paperwidth=8.5in,paperheight=11in,headheight=74pt,top=1.5in]{geometry}% changed
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}% only needed for outdated LaTeX releases
\usepackage{xcolor}
\usepackage{lipsum}
\usepackage{fancyhdr}
\fancyhf{}
\fancyhead[LE,RO]{{\ooalign{%
\color{black!70!white}% background box color
\rule[0.04in]{0.8in}{0.9in}% background box raise, width, height
\cr
\hfil\strut\raisebox{0.25in}{% number raise
\fontfamily{ugq}\selectfont\bfseries\color{white}% number color
\large% number fontsize
\thepage
\kern0.1em% distance number-bar
\kern0.15em% distance bar-totalnumber
\small% totalnumber fontsize
}\hfil
}}}
\fancyheadoffset[LE,RO]{1.2in}% protrusion
\fancyhead[RE]{\leftmark}% added
\fancyhead[LO]{\rightmark}% added
\pagestyle{fancy}
\renewcommand{\headrulewidth}{2pt}
\renewcommand{\footrulewidth}{1pt}
\begin{document}
\chapter{Title}
\section{Title 1}
\begin{quote}
    \lipsum
\end{quote}
\section{Title 2}
\begin{quote}
    \lipsum
\end{quote}
\end{document}
To modify the result of \rightmark and \leftmark, you can redefine \chaptermark and \sectionmark. See the fancyhdr manual for more information.
Sorry, but I can no longer participate here as the administrator is trampling on my wishes on one of his other platforms. :cry:
royer11
Posts: 7
Joined: Tue Jul 23, 2019 12:20 am

how can I create headers configured with fancyhdr

Post by royer11 »

Ijon Tichy wrote:You just have to add \leftmark and/or \rightmark somewhere in your pagestyle definition. However, you also have to change the page geometry, otherwise there is not enough room for such a large head (see the warning of fancyhdr).

Example:
\documentclass[14pt]{extbook}
\usepackage[paperwidth=8.5in,paperheight=11in,headheight=74pt,top=1.5in]{geometry}% changed
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}% only needed for outdated LaTeX releases
\usepackage{xcolor}
\usepackage{lipsum}
\usepackage{fancyhdr}
\fancyhf{}
\fancyhead[LE,RO]{{\ooalign{%
\color{black!70!white}% background box color
\rule[0.04in]{0.8in}{0.9in}% background box raise, width, height
\cr
\hfil\strut\raisebox{0.25in}{% number raise
\fontfamily{ugq}\selectfont\bfseries\color{white}% number color
\large% number fontsize
\thepage
\kern0.1em% distance number-bar
\kern0.15em% distance bar-totalnumber
\small% totalnumber fontsize
}\hfil
}}}
\fancyheadoffset[LE,RO]{1.2in}% protrusion
\fancyhead[RE]{\leftmark}% added
\fancyhead[LO]{\rightmark}% added
\pagestyle{fancy}
\renewcommand{\headrulewidth}{2pt}
\renewcommand{\footrulewidth}{1pt}
\begin{document}
\chapter{Title}
\section{Title 1}
\begin{quote}
    \lipsum
\end{quote}
\section{Title 2}
\begin{quote}
    \lipsum
\end{quote}
\end{document}
To modify the result of \rightmark and \leftmark, you can redefine \chaptermark and \sectionmark. See the fancyhdr manual for more information.
Oh fantastic, tank you
Post Reply