我希望为横向格式的文档添加页眉/页脚。该文档基本上是一张带有少量注释的长表格。请考虑以下示例:
\documentclass[11pt]{article}
\usepackage[utf8]{inputenc}
\usepackage{multirow}
\usepackage{longtable}
\setlength{\textwidth}{16cm}
\setlength{\textheight}{23cm}
\setlength{\oddsidemargin}{0cm}
\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyhf{}
\rhead{My name}
\lhead{document title}
\cfoot{Page \thepage}
\usepackage{geometry}
\geometry{letterpaper,
landscape,
top=2cm,
bottom=2cm,
left=3cm,
right=2cm,
includehead,includefoot,
heightrounded}
\setlength\parindent{0pt}
\begin{document}
\begin{center}
\begin{longtable}{p{2cm}p{4cm}p{1cm}p{2cm}p{4cm}}
\multicolumn{5}{c}{\Large\textbf{Name:} My Name} \\
College:& My college & & University: & My university
\end{longtable}
\vspace{3em}
\begin{large}
Title of document
\end{large}
\end{center}
\begin{footnotesize}
some notes
\end{footnotesize}
\end{document}
但是,如果我只是fancyhdr
从代码中删除该部分,页脚对齐就不会出现问题:
我怎样才能将其fancyhdr
与文档对齐?
答案1
嗯,您的代码中存在一些问题:
如果您使用包,那么您使用的定义就不需要了
geometry
:%\setlength{\textwidth}{16cm} % <======================================= %\setlength{\textheight}{23cm} %\setlength{\oddsidemargin}{0cm}
调用包的顺序
geometry
很fancyhdr
重要!您需要geometry
先调用来定义所有边距。然后可以使用这个正确定义的边距fancyhdr
插入所需的页眉和页脚...\usepackage{geometry} % <=============================================== \geometry{% letterpaper, landscape, top=2cm, bottom=2cm, left=3cm, right=2cm, includehead,includefoot, heightrounded } \usepackage{fancyhdr} % <=============================================== \pagestyle{fancy} \fancyhf{} \rhead{My name} \lhead{document title} \cfoot{Page \thepage}
fancyhdr
在第一页上创建页眉和页脚,并测试页眉和页脚的可用空间是否足够。如果您遇到此情况,您会收到警告(请参阅您的日志文件):Package Fancyhdr Warning: \headheight is too small (12.0pt): Make it at least 13.59999pt.
因此你需要添加以下行
\setlength{\headheight}{14pt} % <=======================================
你的序言……
请参阅以下完整且可编译的 mwe
\documentclass[11pt]{article}
\usepackage[utf8]{inputenc}
\usepackage{multirow}
\usepackage{longtable}
%\setlength{\textwidth}{16cm} % <=======================================
%\setlength{\textheight}{23cm}
%\setlength{\oddsidemargin}{0cm}
\usepackage{geometry} % <===============================================
\geometry{%
letterpaper,
landscape,
top=2cm,
bottom=2cm,
left=3cm,
right=2cm,
includehead,includefoot,
heightrounded
}
\usepackage{fancyhdr} % <===============================================
\pagestyle{fancy}
\fancyhf{}
\rhead{My name}
\lhead{document title}
\cfoot{Page \thepage}
\setlength{\headheight}{14pt} % <=======================================
\setlength\parindent{0pt}
\begin{document}
\begin{center}
\begin{longtable}{p{2cm}p{4cm}p{1cm}p{2cm}p{4cm}}
\multicolumn{5}{c}{\Large\textbf{Name:} My Name} \\
College:& My college & & University: & My university
\end{longtable}
\vspace{3em}
\begin{large}
Title of document
\end{large}
\end{center}
\begin{footnotesize}
some notes
\end{footnotesize}
\clearpage
\begin{footnotesize}
some notes
\end{footnotesize}
\end{document}
及其结果: