我的任务是(自动)渲染具有可选高度的标题。因此我无法理解逻辑 - 标题高度如何工作?
我的标题包含-与我输入的内容parbox
相同 ,因此当高度为 128 时,我得到了这张图片:height
headheight
当高度为 32 时,我得到了
所以我的问题是:如何使页眉顶部与页面顶部精确对齐?
\documentclass{book}
\usepackage{fancybox,fancyhdr}
\usepackage[T1]{fontenc}
\usepackage[dvipsnames]{xcolor}
\usepackage{fixltx2e}
\usepackage[left=72pt,right=72pt,
headheight=124pt,
voffset = 0pt,
textheight =540pt
]{geometry}
\usepackage{array}
\usepackage{showframe}
\fancyhf{}\fancyhead[C]{ \noindent\sbox{0}{\parbox{\textwidth}{\noindent\begin{tabular}{L{\textwidth}{p}}Non-disclosure agreement (NDA)\end{tabular}}}
\ifdim\dimexpr\ht0+\dp0<124pt
\dp0\dimexpr124pt-\ht0\fi
\makebox{\usebox{0}}\\}
\begin{document}
\pagestyle{fancy}
test
\end{document}
答案1
设置为您的和top
的总和。注释掉虚假空格并删除表中的:headheight
\headsep
\tabcolsep
\documentclass{book}
\usepackage{fancybox,fancyhdr}
\usepackage[T1]{fontenc}
\usepackage[dvipsnames]{xcolor}
\usepackage[left=72pt,right=72pt,
headheight=124pt,
top=\dimexpr124pt+\headsep\relax,% <- added
textheight =540pt
]{geometry}
\usepackage{array}
\newcolumntype{L}[2]{>{\raggedright\arraybackslash}{#2}{#1}}
\fancyhf{}
\fancyhead[C]{%
\sbox{0}{\parbox{\textwidth}{\begin{tabular}{@{}L{\textwidth}{p}@{}}Non-disclosure agreement (NDA)\end{tabular}}}%
\ifdim\dimexpr\ht0+\dp0<124pt \dp0\dimexpr124pt-\ht0\fi
\makebox{\usebox{0}}%
}
\usepackage{lipsum}
\usepackage{showframe}
\begin{document}
\pagestyle{fancy}
\lipsum
\end{document}