LaTeX forum ⇒ Page Layouthow can I create headers configured with fancyhdr Topic is solved

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

how can I create headers configured with fancyhdr

Postby royer11 » Tue Jul 23, 2019 8:22 pm

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] [Expand/Collapse] [Download] ({untitled.tex})
  1. \documentclass[14pt]{extbook}
  2. \usepackage[pass,paperwidth=8.5in,paperheight=11in]{geometry}
  3. \usepackage[T1]{fontenc}
  4. \usepackage[utf8]{inputenc}
  5. \usepackage{xcolor}
  6. \usepackage{lipsum}
  7. \usepackage{fancyhdr}

configure fancyhdr
Code: [Select all] [Expand/Collapse] [Download] ({untitled.tex})
  1. \fancyhf{}
  2. \fancyhead[LE,RO]{{\ooalign{%
  3. \color{black!70!white}% background box color
  4. \rule[0.04in]{0.8in}{0.9in}% background box raise, width, height
  5. \cr
  6. \hfil\strut\raisebox{0.25in}{% number raise
  7. \fontfamily{ugq}\selectfont\bfseries\color{white}% number color
  8. \large% number fontsize
  9. \thepage
  10. \kern0.1em% distance number-bar
  11. \kern0.15em% distance bar-totalnumber
  12. \small% totalnumber fontsize
  13. }\hfil
  14. }}}
  15. \fancyheadoffset[LE,RO]{1.2in}% protrusion
  16. \pagestyle{fancy}
  17. \renewcommand{\headrulewidth}{2pt}
  18. \renewcommand{\footrulewidth}{1pt}

and body
Code: [Select all] [Expand/Collapse] [Download] ({untitled.tex})
  1. \begin{document}
  2. \chapter{Title}
  3. \section{Title 1}
  4. \begin{quote}
  5. \lipsum
  6. \end{quote}
  7. \section{Title 2}
  8. \begin{quote}
  9. \lipsum
  10. \end{quote}
  11. \end{document}

reference style
https://tex.stackexchange.com/questions/89666/formatting-page-number-fancyhdr

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

Postby Ijon Tichy » Wed Jul 24, 2019 7:50 am

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:
Code: [Select all] [Expand/Collapse] [Download] (fancyhdr-example.tex)
  1. \documentclass[14pt]{extbook}
  2. \usepackage[paperwidth=8.5in,paperheight=11in,headheight=74pt,top=1.5in]{geometry}% changed
  3. \usepackage[T1]{fontenc}
  4. \usepackage[utf8]{inputenc}% only needed for outdated LaTeX releases
  5. \usepackage{xcolor}
  6. \usepackage{lipsum}
  7. \usepackage{fancyhdr}
  8. \fancyhf{}
  9. \fancyhead[LE,RO]{{\ooalign{%
  10. \color{black!70!white}% background box color
  11. \rule[0.04in]{0.8in}{0.9in}% background box raise, width, height
  12. \cr
  13. \hfil\strut\raisebox{0.25in}{% number raise
  14. \fontfamily{ugq}\selectfont\bfseries\color{white}% number color
  15. \large% number fontsize
  16. \thepage
  17. \kern0.1em% distance number-bar
  18. \kern0.15em% distance bar-totalnumber
  19. \small% totalnumber fontsize
  20. }\hfil
  21. }}}
  22. \fancyheadoffset[LE,RO]{1.2in}% protrusion
  23. \fancyhead[RE]{\leftmark}% added
  24. \fancyhead[LO]{\rightmark}% added
  25. \pagestyle{fancy}
  26. \renewcommand{\headrulewidth}{2pt}
  27. \renewcommand{\footrulewidth}{1pt}
  28. \begin{document}
  29. \chapter{Title}
  30. \section{Title 1}
  31. \begin{quote}
  32. \lipsum
  33. \end{quote}
  34. \section{Title 2}
  35. \begin{quote}
  36. \lipsum
  37. \end{quote}
  38. \end{document}

To modify the result of \rightmark and \leftmark, you can redefine \chaptermark and \sectionmark. See the fancyhdr manual for more information.

royer11
Posts: 4
Joined: Tue Jul 23, 2019 12:20 am

Postby royer11 » Thu Jul 25, 2019 5:29 pm

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:
Code: [Select all] [Expand/Collapse] [Download] (fancyhdr-example.tex)
  1. \documentclass[14pt]{extbook}
  2. \usepackage[paperwidth=8.5in,paperheight=11in,headheight=74pt,top=1.5in]{geometry}% changed
  3. \usepackage[T1]{fontenc}
  4. \usepackage[utf8]{inputenc}% only needed for outdated LaTeX releases
  5. \usepackage{xcolor}
  6. \usepackage{lipsum}
  7. \usepackage{fancyhdr}
  8. \fancyhf{}
  9. \fancyhead[LE,RO]{{\ooalign{%
  10. \color{black!70!white}% background box color
  11. \rule[0.04in]{0.8in}{0.9in}% background box raise, width, height
  12. \cr
  13. \hfil\strut\raisebox{0.25in}{% number raise
  14. \fontfamily{ugq}\selectfont\bfseries\color{white}% number color
  15. \large% number fontsize
  16. \thepage
  17. \kern0.1em% distance number-bar
  18. \kern0.15em% distance bar-totalnumber
  19. \small% totalnumber fontsize
  20. }\hfil
  21. }}}
  22. \fancyheadoffset[LE,RO]{1.2in}% protrusion
  23. \fancyhead[RE]{\leftmark}% added
  24. \fancyhead[LO]{\rightmark}% added
  25. \pagestyle{fancy}
  26. \renewcommand{\headrulewidth}{2pt}
  27. \renewcommand{\footrulewidth}{1pt}
  28. \begin{document}
  29. \chapter{Title}
  30. \section{Title 1}
  31. \begin{quote}
  32. \lipsum
  33. \end{quote}
  34. \section{Title 2}
  35. \begin{quote}
  36. \lipsum
  37. \end{quote}
  38. \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


Return to “Page Layout”

Who is online

Users browsing this forum: No registered users and 2 guests