如何调整页面大小以便将较大的页眉和页脚放入页面中?

如何调整页面大小以便将较大的页眉和页脚放入页面中?

我正在使用 fancyhdr 创建两种页面样式。第一页将有一个备忘录标题。公司徽标、收件人、组织名称等。之后,我想要一个更简化的页眉和页脚。出于某种原因,我可以让页眉适合,但文本溢出并破坏了页脚。我查看了页面大小和边距的图表。

我想简单地认为 headsize+footsize+textsize = pagesize。我试过缩小 textsize,但我的页脚似乎仍然消失了。我希望有人能帮我解决这个问题。

下面我有一个简单的例子(但有评论):

\documentclass[11pt]{article}
\usepackage{graphicx}
\usepackage{fancyhdr}
\renewcommand{\headrulewidth}{0pt}
\renewcommand{\footrulewidth}{0pt}
\usepackage{color,colortbl}
\usepackage{fix-cm}
\usepackage{setspace}
\usepackage{lipsum}
\usepackage{blindtext}
\usepackage[letterpaper,margin=0.5in]{geometry}


%%%%%%%%%%%%%%%%%%%%%
% PAGE STYLE       %%
%%%%%%%%%%%%%%%%%%%%%
\fancypagestyle{firstpage}
  {%First page definitions
    \newgeometry{left=0.5in, right=0.5in, top=2.8in, bmargin=3.8in,headheight=179.1pt}
    
    
      %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
      %                  HEADERS                             %
      %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

      %%%%%RIGHT SIDE HEADER%%%%%
      \fancyhead[R]{
        \begin{tabular}{r@{}c@{}l}
          \textit{To}: & Jane Doe, ABC-DE, PO 5125\\
          \textit{From}: &John Doe, ABC-DEF, PO 5125\\
          &Heather Doe, ABC-DEF, PO 5125\\
          &W. Sam Doe, ABC-DEF, PO 5126\\
          \textit{Thru}: &Chip Doe, ABC-DEF, PO 5126\\
          \textit{Phone}: &(800)867-5309\\
          \textit{Symbol}: &ABC-DEF:2021-XXXX\\
          \textit{Date}: &\today \\
        \end{tabular}
      }
          %%%%%END RIGHT SIDE HEADER%%%%%

  %%%%%LEFT SIDE HEADER%%%%%
      \fancyhead[LH]{\vspace{1cm}ABC-DEF:2021-XXXXX \\ \vspace{1cm}
    \includegraphics[width=0.3\textwidth]{somepic.png}\\
                    \vspace{0.1cm}{\Large\textbf{memorandum}}\\
                    ORG-NAM, SOME ORGANIZATION
  }
  %%%%%END LEFT SIDE HEADER%%%%%

  %%%%%CENTER HEADER%%%%%
  \chead[C]{}
  %%%%%END CENTER HEADER%%%%%

  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  %                  FOOTERS                             %
  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  

  %%%%%%%%CENTER FOOTER%%%%%%%%%%%%%%
  \cfoot[C]{}
  %%%%%%%%END CENTER FOOTER%%%%%%%%%%%%%%

  %%%%%LEFT SIDE FOOTER%%%%%
  \lfoot{\vspace{0cm}\fbox{
        \begin{minipage}[c]{0.45\textwidth}
          \begin{center}
            {\large\textbf{BLAH}}
          \end{center}
          blah blah blah blah blah blah blah blah blah blah blah
        \end{minipage}
      }%End of fbox
    }
  %%%%%END LEFT SIDE FOOTER%%%%%

  %%%%%RIGHT SIDE FOOTER%%%%%
  \fancyfoot[R]{\vspace{0cm}\fbox{\raggedright
        \begin{minipage}[r]{0.4\textwidth}
          \begin{center}
            {\large \textbf{Chief Editor}}
          \end{center}
          \textbf{Brought to you by:} ME\\
          \textbf{Original:} XZ-ORG1-COMPANY\\
        \end{minipage}
      }%end of fbox
    }
    %%%%%END RIGHT SIDE FOOTER%%%%%
  
}%End of first page definitions


\fancypagestyle{otherpages}{%all otherpages
    \setlength{\headheight}{57.7pt}
  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  %                  HEADERS                             %
  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

  %%%%%RIGHT SIDE HEADER%%%%%
  \fancyhead[R]{\today}
  %%%%%END RIGHT SIDE HEADER%%%%%

  %%%%%LEFT SIDE HEADER%%%%%
  \fancyhead[LH]{\vspace{1cm}ABC-DEF: 2021-XXXXX}
  %%%%%END LEFT SIDE HEADER%%%%%

  %%%%%CENTER HEADER%%%%%
   \fancyhead[C]{{\Huge\color{red}\textbf{HEAD/ER}}\\-\thepage}
   %%%%%END CENTER HEADER%%%%%

  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  %                  FOOTERS                             %
  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  
  %%%%%%%%CENTER FOOTER%%%%%%%%%%%%%%
  \cfoot[C]{\Huge\color{red}\textbf{FOOT/ER}}
  %%%%%%%%END CENTER FOOTER%%%%%%%%%%%%%%


  %%%%%LEFT SIDE FOOTER%%%%%
  \fancyfoot[L]{}
  %%%%%END LEFT SIDE FOOTER%%%%%

  %%%%%RIGHT SIDE FOOTER%%%%%
  \fancyfoot[R]{}
  %%%%%END RIGHT SIDE FOOTER%%%%%
  
}%end of all other pages


%%End of first page definition
\pagestyle{otherpages}
\thispagestyle{firstpage}

\begin{document}

{\Large \textbf{Subject: (U) poop}}
\vspace{0.5cm}

\Blindtext
\lipsum[1-10]

\end{document}

答案1

我对一些花哨的标题定义做了一些更改,但主要是对包的实现做了更改geometry

如果您不手动通过\restoregeometry在文本中的正确位置插入(它本身会开始一个新页面)来恢复第二页上的默认几何形状并不是一件容易的事。

但是,在这种情况下,使用该包的解决方案afterpage似乎有效(来自https://tex.stackexchange.com/a/358322/161015

a2

b

\documentclass[11pt]{article}
\usepackage{graphicx}
\usepackage{fancyhdr}
\renewcommand{\headrulewidth}{0pt}
\renewcommand{\footrulewidth}{0pt}
\usepackage{color,colortbl}
\usepackage{fix-cm}
\usepackage{setspace}
\usepackage{lipsum}
\usepackage{blindtext}

\usepackage{showframe} % to show margins. Comment this line to clear  <<<<
\usepackage{afterpage} % needed <<<<<<<<<<<

\usepackage[letterpaper,left=0.5in, right=0.5in, top=1.5in, bottom=1.2in,headheight=0.8in]{geometry} % changed <<<

%%%%%%%%%%%%%%%%%%%%%
% PAGE STYLE       %%
%%%%%%%%%%%%%%%%%%%%%
\fancypagestyle{firstpage}
{%First page definitions    
    \fancyhf{}
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    %                  HEADERS                             %
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    
    %%%%%RIGHT SIDE HEADER%%%%%
    \fancyhead[R]{%% changed to align second column <<<<<<<
        \begin{tabular}{rl}
            \textit{To}: & Jane Doe, ABC-DE, PO 5125\\
            \textit{From}: &John Doe, ABC-DEF, PO 5125\\
            &Heather Doe, ABC-DEF, PO 5125\\
            &W. Sam Doe, ABC-DEF, PO 5126\\
            \textit{Thru}: &Chip Doe, ABC-DEF, PO 5126\\
            \textit{Phone}: &(800)867-5309\\
            \textit{Symbol}: &ABC-DEF:2021-XXXX\\
            \textit{Date}: &\today \\
        \end{tabular}
    }
    %%%%%END RIGHT SIDE HEADER%%%%%
    
    %%%%%LEFT SIDE HEADER%%%%%
    \fancyhead[L]{%% changed <<<<<<
        \begin{tabular}{@{}l}
        ABC-DEF:2021-XXXXX \\[5pt]
        \includegraphics[width=0.3\textwidth]{example-image}\\[5pt]
        \Large\textbf{memorandum}\\[5pt]
        ORG-NAM, SOME ORGANIZATION
    \end{tabular}
    }
    %%%%%END LEFT SIDE HEADER%%%%%
    
    %%%%%CENTER HEADER%%%%%
    \chead[C]{}
    %%%%%END CENTER HEADER%%%%%
    
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    %                  FOOTERS                             %
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%    
    
    %%%%%%%%CENTER FOOTER%%%%%%%%%%%%%%
    \cfoot[C]{}
    %%%%%%%%END CENTER FOOTER%%%%%%%%%%%%%%
    
    %%%%%LEFT SIDE FOOTER%%%%%
\fancyfoot[L]{\vspace*{0pt}\fbox{% changed <<<<<<
            \begin{minipage}[c]{0.45\textwidth}                 \
            \centering\textbf{BLAH}\\                                       
            \raggedright    blah blah blah blah blah blah blah blah blah blah blah
            \end{minipage}
        }%End of fbox
    }
    %%%%%END LEFT SIDE FOOTER%%%%%
    
    %%%%%RIGHT SIDE FOOTER%%%%%
    \fancyfoot[R]{\vspace*{0pt}\fbox{%
            \begin{minipage}[r]{0.4\textwidth}              
                \centering\large \textbf{Chief Editor}\\                
                \raggedright    \textbf{Brought to you by:} ME\\
                \textbf{Original:} XZ-ORG1-COMPANY
            \end{minipage}
        }%end of fbox
    }
    %%%%%END RIGHT SIDE FOOTER%%%%%
    
}%End of first page definitions


\fancypagestyle{otherpages}{%all otherpages
\fancyhf{}
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    %                  HEADERS                             %
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    
    %%%%%RIGHT SIDE HEADER%%%%%
    \fancyhead[R]{\today}
    %%%%%END RIGHT SIDE HEADER%%%%%
    
    %%%%%LEFT SIDE HEADER%%%%%
    \fancyhead[LH]{\vspace{1cm}ABC-DEF: 2021-XXXXX}
    %%%%%END LEFT SIDE HEADER%%%%%
    
    %%%%%CENTER HEADER%%%%%
    \fancyhead[C]{{\Huge\color{red}\textbf{HEAD/ER}}\\-\thepage}
    %%%%%END CENTER HEADER%%%%%
    
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    %                  FOOTERS                             %
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    
    %%%%%%%%CENTER FOOTER%%%%%%%%%%%%%%
    \fancyfoot[C]{\Huge\color{red}\textbf{FOOT/ER}}
    %%%%%%%%END CENTER FOOTER%%%%%%%%%%%%%%
    
    
    %%%%%LEFT SIDE FOOTER%%%%%
    \fancyfoot[L]{}
    %%%%%END LEFT SIDE FOOTER%%%%%
    
    %%%%%RIGHT SIDE FOOTER%%%%%
    \fancyfoot[R]{}
    %%%%%END RIGHT SIDE FOOTER%%%%%
    
}%end of all other pages

%%End of first page definition
\pagestyle{otherpages} % activate style to by used from the second page

\begin{document}
    
\thispagestyle{firstpage}
\newgeometry{letterpaper,left=0.5in, right=0.5in, top=3.5in, bottom=1.8in,headheight=2.5in}
{\noindent\Large \textbf{Subject: (U) poop}}
\vspace{0.5cm}

\afterpage{\globaldefs=1 \restoregeometry} % see reference https://tex.stackexchange.com/a/358322/161015

\lipsum[1-10]
    
\end{document}

作为一个更简单的第二种选择,无需使用afterpagenor \restoregeometry,您可以在第一页上留出一些垂直空间,为扩展标题腾出空间,然后 \pagestyle{otherpages}从第二页开始。 (类似于这个答案https://tex.stackexchange.com/a/577066/161015

d2

使用相同的序言

\begin{document}
    
\vspace*{1.5in} % added <<<<<<<<

\thispagestyle{firstpage}
{\noindent\Large \textbf{Subject: (U) poop}}
\vspace{0.5cm}  
    
\lipsum[1-10]
    
\end{document}

答案2

如果您用来geometry放大页眉和/或页脚,通常建议包含该includeheadfoot选项,以便geometry能够适应textheight

对于第一页,我建议将页眉中的内容firstpage放在后面的正文中,而不是页眉中\begin{document}。如果您想在序言中指定它,则可以将其放在中\AtBeginDocument{...}

如果您仍想使用页眉,我的建议是欺骗 LaTeX,使页眉看起来具有正常的页眉高度(例如 10pt),并省略\newgeometry。这样,您可以在所有页面上使用相同的几何图形。但随后您必须通过在文档开头使用 来弥补\vspace实际的页眉高度。

您可以通过将标题高度放入 中\raisebox并指定所需的高度(例如 10pt)和深度(0pt)来伪造标题高度。由于\raisebox仅接受水平材料,您必须将左标题放在 内\parbox\raisebox您将需要稍微调整框的升高量以获得正确的定位。

这是一个粗略的例子。

\documentclass[11pt]{article}
\usepackage{graphicx}
\usepackage{fancyhdr}
\renewcommand{\headrulewidth}{0pt}
\renewcommand{\footrulewidth}{0pt}
\usepackage{color,colortbl}
\usepackage{fix-cm}
\usepackage{setspace}
\usepackage{lipsum}
\usepackage{blindtext}
\usepackage[letterpaper,margin=0.5in]{geometry}


%%%%%%%%%%%%%%%%%%%%%
% PAGE STYLE       %%
%%%%%%%%%%%%%%%%%%%%%
\fancypagestyle{firstpage}
  {%First page definitions
      %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
      %                  HEADERS                             %
      %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

      %%%%%RIGHT SIDE HEADER%%%%%
      \fancyhead[R]{\raisebox{-5cm}[10pt][0pt]{%
        \begin{tabular}{r@{}c@{}l}
          \textit{To}: & Jane Doe, ABC-DE, PO 5125\\
          \textit{From}: &John Doe, ABC-DEF, PO 5125\\
          &Heather Doe, ABC-DEF, PO 5125\\
          &W. Sam Doe, ABC-DEF, PO 5126\\
          \textit{Thru}: &Chip Doe, ABC-DEF, PO 5126\\
          \textit{Phone}: &(800)867-5309\\
          \textit{Symbol}: &ABC-DEF:2021-XXXX\\
          \textit{Date}: &\today \\
        \end{tabular}}
      }
          %%%%%END RIGHT SIDE HEADER%%%%%

  %%%%%LEFT SIDE HEADER%%%%%
      \fancyhead[L]{\raisebox{-3cm}[10pt][0pt]{\parbox{0.5\headwidth}{\vspace{1cm}ABC-DEF:2021-XXXXX \\ [1cm]
    \includegraphics[width=0.3\textwidth]{example-image}\\
                    \vspace{0.1cm}{\Large\textbf{memorandum}}\\
                    ORG-NAM, SOME ORGANIZATION
  }}}
  %%%%%END LEFT SIDE HEADER%%%%%

  %%%%%CENTER HEADER%%%%%
  \chead[C]{}
  %%%%%END CENTER HEADER%%%%%

  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  %                  FOOTERS                             %
  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  

  %%%%%%%%CENTER FOOTER%%%%%%%%%%%%%%
  \cfoot[C]{}
  %%%%%%%%END CENTER FOOTER%%%%%%%%%%%%%%

  %%%%%LEFT SIDE FOOTER%%%%%
  \lfoot{\vspace{0cm}\fbox{
        \begin{minipage}[c]{0.45\textwidth}
          \begin{center}
            {\large\textbf{BLAH}}
          \end{center}
          blah blah blah blah blah blah blah blah blah blah blah
        \end{minipage}
      }%End of fbox
    }
  %%%%%END LEFT SIDE FOOTER%%%%%

  %%%%%RIGHT SIDE FOOTER%%%%%
  \fancyfoot[R]{\raisebox{-40pt}[10pt]{\fbox{\raggedright
        \begin{minipage}[r]{0.4\textwidth}
          \begin{center}
            {\large \textbf{Chief Editor}}
          \end{center}
          \textbf{Brought to you by:} ME\\
          \textbf{Original:} XZ-ORG1-COMPANY\\
        \end{minipage}
      }%end of fbox
    }}
    %%%%%END RIGHT SIDE FOOTER%%%%%
  
}%End of first page definitions


\fancypagestyle{otherpages}{%all otherpages
    \setlength{\headheight}{57.7pt}
  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  %                  HEADERS                             %
  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

  %%%%%RIGHT SIDE HEADER%%%%%
  \fancyhead[R]{\today}
  %%%%%END RIGHT SIDE HEADER%%%%%

  %%%%%LEFT SIDE HEADER%%%%%
  \fancyhead[LH]{\vspace{1cm}ABC-DEF: 2021-XXXXX}
  %%%%%END LEFT SIDE HEADER%%%%%

  %%%%%CENTER HEADER%%%%%
   \fancyhead[C]{{\Huge\color{red}\textbf{HEAD/ER}}\\-\thepage}
   %%%%%END CENTER HEADER%%%%%

  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  %                  FOOTERS                             %
  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  
  %%%%%%%%CENTER FOOTER%%%%%%%%%%%%%%
  \cfoot[C]{\Huge\color{red}\textbf{FOOT/ER}}
  %%%%%%%%END CENTER FOOTER%%%%%%%%%%%%%%


  %%%%%LEFT SIDE FOOTER%%%%%
  \fancyfoot[L]{}
  %%%%%END LEFT SIDE FOOTER%%%%%

  %%%%%RIGHT SIDE FOOTER%%%%%
  \fancyfoot[R]{}
  %%%%%END RIGHT SIDE FOOTER%%%%%
  
}%end of all other pages


%%End of first page definition
\pagestyle{otherpages}

\begin{document}
\thispagestyle{firstpage}

\vspace*{7cm}

{\Large \textbf{Subject: (U) poop}}
\vspace{0.5cm}

\Blindtext
\lipsum[1-10]

\end{document}

在此处输入图片描述

相关内容