修复标题位置,忽略边距变化

修复标题位置,忽略边距变化

我编写了一个文档/工作簿,当页面间距为 1 列和 2 列时,使用不同的边距。我使用 {geometry} 包与 {multicol} 控件组合实现了这一点。

当我后来在序言中添加页眉时,它会根据定义的边距在页面上编译。换句话说,页眉的位置似乎与我定义边距的方式有关,但我希望页眉在页面上处于固定位置,无论我使用哪种边距设计。

有没有办法创建一个与页角始终保持固定距离的页眉/页脚,以便当我更改边距时页眉/页脚不会改变位置?

我尝试添加一个最小化的代码示例来演示。它可能比必要的更长,因为我想包含我正在研究的“关键”空间特征。

\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}''''

答案1

页眉和页脚始终相对于文本主体定位。但是,fancyhdr可以使用命令\fancyhfoffset(或\fancyheadoffset \fancyfootoffset)定义页眉和页脚字段相对于此的偏移量。

因此,解决方案是定义两种页面样式,一种用于单列情况,一种用于双列情况,并\fancyhfoffsets在其中放入不同的内容。如果其余的页眉/页脚在两种情况下都相同,则可以将其保留在这些之外,或者将其放入两个定义中。

\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}

在此处输入图片描述

在此处输入图片描述

相关内容