如何添加全宽页眉?

如何添加全宽页眉?

我想添加一个包含图片(与文本左对齐)、多行文本和图片(与文本右对齐)的标题。我发现fancyhdr它的文档复杂得令人无法接受,我希望有人有经验。我希望整个标题有一个覆盖整个标题的蓝色背景textwidth(因此放入图片lhead似乎rhead没有用。我的标记如下所示:

\usepackage{fancyhdr}
\definecolor{arylideyellow}{rgb}{0.91, 0.84, 0.42}
\newcommand{\myboxheader}[1]{{\color{blue} #1}}
\newcommand{\mybox}[1]{\fcolorbox{gray}{arylideyellow}{#1}}
\pagestyle{fancy}
%\lhead{\colorbox{blue}{\includegraphics[height=1cm]{logo1.png} }}
\chead{\makebox[\textwidth]{\colorbox{blue}{\includegraphics[height=1cm]{logo1.png} \hfill my multiline header (multiline with \newline or \\?) \hfill \includegraphics[height=1cm]{logo2.png} }}}
%\rhead{\colorbox{blue}{\includegraphics[height=1cm]{logo2.png} }}
\cfoot{I don't care for the footer so far!}

\begin{document}
...
\end{document}

它没有将两张图片充分地向左和向右移动,以便它们与文本边框对齐。

我检查了类似这样的问题如何在 fancyhdr 中增加 headrule 长度?或者http://www.latex-community.org/forum/viewtopic.php?f=45&t=6204但是他们都假设人们能够理解这个庞大的变量集的结构,而这些变量在文档中彼此之间没有足够的关联,但这并不适用于我……

评论附录:

徽标 A、B 和中心部分之间的间隙的屏幕截图

徽标 A、B 和中心部分之间的间隙的屏幕截图。我用“中心部分”来指代徽标以外的所有内容。

答案1

在下面的例子中,我使用Left 标题设置蓝色背景,并使用enter 标题在两侧放置两个徽标,并在中间C放置多行。\parbox

在此处输入图片描述

\documentclass{article}
\usepackage[paper=a6paper,margin=1cm,includeheadfoot]{geometry}% Just for this example
\usepackage{fancyhdr,xcolor,graphicx}
\definecolor{arylideyellow}{rgb}{0.91, 0.84, 0.42}
\newcommand{\myboxheader}[1]{{\color{blue} #1}}
\newcommand{\mybox}[1]{\fcolorbox{gray}{arylideyellow}{#1}}
\pagestyle{fancy}
\fancyhead[L]{\color{blue}{\rule{\textwidth}{1cm}}}% Set blue background
\fancyhead[C]{%
  \makebox[\textwidth]{%
    \includegraphics[height=1cm]{example-image-a}%
    \hfill%
    \parbox[b]{\dimexpr\textwidth-3cm}{my multi-line header of text \\ some more text}%
    \hfill%
    \includegraphics[height=1cm]{example-image-b}}}
\setlength{\headheight}{35pt}
\fancyfoot[C]{I don't care for the footer so far!}

\begin{document}
Lorem ipsum
\end{document}

您必须\headheight根据标题内容的大小进行设置。我刚刚编译,LaTeX 建议将其设置为“至少 X pt”,因此我相应地进行了设置。如果您使用geometry彻底地。

蓝色背景(与 logos/ 等同的全宽和高度的蓝色规则1cm)的两端都被徽标覆盖,因为它们的高度完全相同。

fancyhdr将页眉内容放在三个框中:左页眉位于一个与右侧重叠的零宽度框中;右页眉位于一个与左侧重叠的零宽度框中;中间页眉位于一个\headwidth居中的宽度框中。实际上,左、右页眉也位于宽度为 的框中\headwidth,但重叠可避免输出错误。页脚使用类似的设置。

相关内容