Text Formattingfancyhdr | Make Header as wide as the Text

Information and discussion about LaTeX's general text formatting features (e.g. bold, italic, enumerations, ...)
Post Reply
chrisr34000
Posts: 10
Joined: Mon Aug 15, 2011 9:40 pm

fancyhdr | Make Header as wide as the Text

Post by chrisr34000 »

Hello!

I have the following header:

Code: Select all

\usepackage{fancyhdr}
\fancyhf{}
\fancyhead[L]{\bfseries \nouppercase \leftmark}
\fancyhead[R]{\bfseries \thepage}
\setlength{\headheight}{16pt}
\pagestyle{fancy}
\renewcommand{\headrulewidth}{0.5pt}
\fancyheadoffset{\marginparwidth - 1.05cm}
and my page settings are:

Code: Select all

\setlength{\unitlength}{1cm}
\setlength{\oddsidemargin}{0.3cm}
\setlength{\evensidemargin}{0.3cm}
\setlength{\textwidth}{15.5cm}
\setlength{\topmargin}{-1.2cm}
\setlength{\textheight}{24.5cm}
\columnsep 0.5cm
How do I set

Code: Select all

\fancyheadoffset
to be as wide as a text line can be (maximum width of a textline) ?

Chris

Recommended reading 2024:

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

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

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

beethovengg
Posts: 8
Joined: Tue Nov 16, 2010 4:55 am

Re: fancyhdr | Make Header as wide as the Text

Post by beethovengg »

pls read again fancyhdr package -- there are many tips there...

what is the size of your paper? (\paperwidth and \paperheight)

since you have set already your \textwidth and other margin parameters, you can calculate the "margin" at the left and the margin at the right.

then use the command, e.g.,

\fancyheadoffset[RO,LE]{0.5in}

which will add 0.5in to the right header for odd pages, and to the left header for even pages. All these and other combinations are discussed in the fancyhdr package. it also depends if you have the option oneside or twoside (pls read package)

u can also use calc package so you can do "calculations" with lengths and margins.

hope this helps.
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

fancyhdr | Make Header as wide as the Text

Post by localghost »

chrisr34000 wrote:[…] and my page settings are:

Code: Select all

\setlength{\unitlength}{1cm}
\setlength{\oddsidemargin}{0.3cm}
\setlength{\evensidemargin}{0.3cm}
\setlength{\textwidth}{15.5cm}
\setlength{\topmargin}{-1.2cm}
\setlength{\textheight}{24.5cm}
\columnsep 0.5cm
[…]
Those settings for the type area are preferably done by the geometry package. Your problem then might vanish.


Thorsten
Post Reply