1

I need a way to set the font size to any custom value like what can be achieved with \changefontsize from fontsize package. The problem of fontsize is that it does not affect the font size in the header and footer. There is also the extsizes package, but in my quick test, using extarticle documentclass only the header and footer have been affected.

here is my mwe:

\documentclass[a4paper]{article}
\usepackage{fontsize,fix-cm,fancyhdr}
\changefontsize{18}

\pagestyle{fancy}
\fancyhf{}
\fancyhead[R]{header}
\fancyfoot[C]{\thepage{}}

\begin{document}
document body
\end{document}

2 Answers 2

3

In general you want to tell LaTeX what font size you want in headers and footers.

\RequirePackage{fix-cm}
\documentclass[a4paper]{article}
\usepackage{fontsize,fancyhdr}
\changefontsize{18}

\pagestyle{fancy}
\fancyhf{}
\fancyhead[R]{\footnotesize header \fontname\font}
\fancyfoot[C]{\footnotesize\thepage}
\setlength{\headheight}{18pt}

\begin{document}
document body
\end{document}

enter image description here

Otherwise, fix a bug in fancyhdr.sty that uses \@normalsize when it shouldn't.

\RequirePackage{fix-cm}
\documentclass[a4paper,12pt]{article}
\usepackage{fontsize,fancyhdr}
\changefontsize{18}

\makeatletter
\let\@normalsize\normalsize
\makeatother

\fancyhf{}
\fancyhead[R]{header \fontname\font}
\fancyfoot[C]{\thepage}
\pagestyle{fancy}

\begin{document}
document body
\end{document}

enter image description here

Explanation: older (in the sense of very old) versions of LaTeX used \@normalsize, but nowadays only \normalsize should be used anywhere.

Of course, you'll have to cope with the important warning

Package fancyhdr Warning: \headheight is too small (12.0pt):
(fancyhdr)                Make it at least 21.59993pt, for example:
(fancyhdr)                \setlength{\headheight}{21.59993pt}.
(fancyhdr)                You might also make \topmargin smaller to compensate:
(fancyhdr)                \addtolength{\topmargin}{-9.59993pt}.
6
  • no, i want to set the document font size such that, that one setting is affecting the header and footer too. Commented Sep 14, 2022 at 12:22
  • in your solution, look, the size is not the same for the document body and the header. Commented Sep 14, 2022 at 12:24
  • @user1850133 then replace \footnotesze by \normalsize you need it to trigger the fontsize function correctly.
    – daleif
    Commented Sep 14, 2022 at 12:49
  • @user1850133 I added a way. But you should set the size anyway. Your first comment was a bit rude, wasn't it? Something like “Sorry, I'd like to…” would have avoided the rudeness.
    – egreg
    Commented Sep 14, 2022 at 12:55
  • yes that works when the \let\@normalsize\normalsize is after the \changefontsize... command Commented Sep 14, 2022 at 13:04
0

What you want (one only setting for all) is:

\documentclass[a4paper,17pt]{extarticle}

or

\documentclass[a4paper,17pt]{extarticle}

Unfortunately, you cannot use 18pt here, only the same sizes that using extsizes:, i.e., 8pt, 9pt, 10pt, 11pt, 12pt, 14pt, 17pt, and 20pt

If you want exactly 18pt you will need a scalable font (e.g., the libertine libertine package) and use a Koma class:

\documentclass[a4paper,fontsize=18pt]{scrartcl}
\usepackage{libertine}
\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyhf{}
\fancyhead[R]{header}
\fancyfoot[C]{\thepage{}}
\begin{document}
document body
\end{document}

However, wouldn't it be easier for you to simply add \changefontsize{18} also in the footer and the header?

You must log in to answer this question.

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