0

I have written a document/workbook that uses different margin spacing for when it has 1 column page spacing and 2 column page spacing. I did this using the {geometry} package is combination with {multicol} controls.

When I later went to add a header in the preamble it would compile on pages based on the margins that were defined. In other words, the position of the header seems to be bound to the way I define the margins, but I want the header to be in a fixed position on the page, regardless of which margin design I'm using.

Is there a way to create a header/footer that is ALWAYS a fixed distance from the page corners so that when I change the margins the header/footer don't change position?

I am adding an attempt at a minimized code example to demonstrate. It might be longer than necessary because I wanted to include the "key" spatial features I was working around.

\usepackage[a4paper,margin=1in,headheight=33pt,headsep=12pt,heightrounded]{geometry}
    \usepackage{multicol} 
    \setlength{\columnsep}{2.25cm}
    \usepackage{changepage} 

\usepackage{lipsum}

%this code is included to show an important feature of the page spacing I want, subsection title
\usepackage[dvipsnames]{xcolor} 
\usepackage{titlesec}
\newcommand*{\justifyheading}{\raggedleft}
\titleformat*{\subsection}
    {\fontsize{36}{18}\color{Gray}\justifyheading\fontfamily{qhv}\selectfont} 

%this code is included to show an important feature of the page spacing I want, custom enumeration
\makeatletter 
\renewcommand\Huge{\@setfontsize\Huge{36pt}{18}}
\makeatother
\usepackage{enumitem}
\newlist{enumerateP1}{enumerate}{1} 
\setlist[enumerateP1]{
    label=\raisebox{-8pt}{\Huge\color{gray}\arabic*},
        topsep=1cm, 
        itemsep=0.75cm, 
    ref=\arabic*
}

%my most current header attempt
\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyhf{}

\fancyhead[LO]{Odd Page, Upper Left Corner}
\fancyhead[RE]{Even Page, Upper Right Corner}
\fancyfoot[LO,RE]{\thepage}
\renewcommand{\headrulewidth}{0pt}


%the document body might be longer than it needs to be but I wanted to be able to demonstrate the goal of left and right pages.

\begin{document}

\newgeometry{left=1.5in, right=1.5in, bottom=0.75in, top=0.75in}

\subsection*{SingleColSection}

\lipsum[100]
\vfill
\phantom{tacocat}
\pagebreak

\lipsum[100]
\vfill
\phantom{tacocat}
\pagebreak

\newgeometry{outer=0.5in, inner=1in, bottom=0.75in, top=0.75in}

\subsection*{TwoColSection}

\begin{enumerateP1}[resume]  
 \begin{multicols}{2}

\item \lipsum[90] 
\item \lipsum[90] 
\item \lipsum[90] 
\item \lipsum[90] 
\item \lipsum[90] 

\end{multicols}
\end{enumerateP1}

\end{document}''''
3
  • Please provide an MWE (from \documentclass... to \end{document}) that we can compile that shows your problem and what you have tried. Jul 31, 2022 at 17:05
  • Specify the left of the header as at xpt and the right of the header as at \paperwidth - ypt. Hopefully someone else can help you better. Jul 31, 2022 at 17:26
  • Thank you for the reply. Unfortunately I either did not understand your suggestion or I did not implement it correctly. I've edited the post to include the general code and structure I'm working with. I apologize if I included more than I should have.
    – Tom Brown
    Jul 31, 2022 at 19:29

1 Answer 1

0

The page headers and footers are always positioned relative to the text body. However, fancyhdr can define the offsets of the header and footer fields relative to this with the command \fancyhfoffset (or \fancyheadoffset \fancyfootoffset).

So the solution is to define two pagestyles, one for the single column case and one for the two column case, and put different \fancyhfoffsets in them. If the rest of the headers/footers is the same in both cases you can keep that outside of these, or alternatively, put it in both definitions.

\documentclass{book}
\usepackage[a4paper,margin=1in,headheight=33pt,headsep=12pt,heightrounded]{geometry}
    \usepackage{multicol} 
    \setlength{\columnsep}{2.25cm}
    \usepackage{changepage} 

\usepackage{lipsum}

%this code is included to show an important feature of the page spacing I want, subsection title
\usepackage[dvipsnames]{xcolor} 
\usepackage{titlesec}
\newcommand*{\justifyheading}{\raggedleft}
\titleformat*{\subsection}
    {\fontsize{36}{18}\color{Gray}\justifyheading\fontfamily{qhv}\selectfont} 

%this code is included to show an important feature of the page spacing I want, custom enumeration
\makeatletter 
\renewcommand\Huge{\@setfontsize\Huge{36pt}{18}}
\makeatother
\usepackage{enumitem}
\newlist{enumerateP1}{enumerate}{1} 
\setlist[enumerateP1]{
    label=\raisebox{-8pt}{\Huge\color{gray}\arabic*},
        topsep=1cm, 
        itemsep=0.75cm, 
    ref=\arabic*
}

%my most current header attempt
\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyhf{}

% Common pagestyle values
\fancyhead[LO]{Odd Page, Upper Left Corner}
\fancyhead[RE]{Even Page, Upper Right Corner}
\fancyfoot[LO,RE]{\thepage}
\renewcommand{\headrulewidth}{0pt}

\fancypagestyle{singlecol}{%
  \fancyhfoffset{0pt}
}
\fancypagestyle{twocol}{%
  \fancyhfoffset[LO,RE]{-0.5in}
}
%the document body might be longer than it needs to be but I wanted to be able to demonstrate the goal of left and right pages.

\begin{document}

\newgeometry{left=1.5in, right=1.5in, bottom=0.75in, top=0.75in}
\pagestyle{singlecol}

\subsection*{SingleColSection}

\lipsum
\vfill
\phantom{tacocat}
\pagebreak

\lipsum
\vfill
\phantom{tacocat}
\pagebreak

\newgeometry{outer=0.5in, inner=1in, bottom=0.75in, top=0.75in}
\pagestyle{twocol}

\subsection*{TwoColSection}

\begin{enumerateP1}[resume]  
 \begin{multicols}{2}

\item \lipsum[90]
\item \lipsum[90] 
\item \lipsum[90] 
\item \lipsum[90] 
\item \lipsum[90] 
\item \lipsum

\end{multicols}
\end{enumerateP1}

\end{document}

enter image description here

enter image description here

You must log in to answer this question.

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