如何获取头部的图像?

如何获取头部的图像?

我怎样才能获得这样的头部,其中的图像一直到纸张的边缘,并且具有与图像相似的渐变?

在此处输入图片描述

我曾经多次使用过fancyhdr包,但是......以一种非常简单的方式,仅使用文本(右中或左)。

答案1

一个解决方案mdframed

梅威瑟:

\documentclass{article}
\usepackage{graphicx}
\usepackage[framemethod=tikz]{mdframed}

\usepackage{fancyhdr}
\let\oldheadrule\headrule
\renewcommand{\headrule}{\vskip-3\baselineskip\oldheadrule}
\renewcommand\headrulewidth{0pt}
\fancyhf{}
\fancyhead[C]{%
\begin{mdframed}[%
    innertopmargin=0pt,
    innerbottommargin=0pt,
    innerleftmargin=0pt,
    tikzsetting={shade,left color=blue!50,right color=blue!10}
    ]
\includegraphics[scale=0.05]{example-image-a}\hfill\raisebox{.3\baselineskip}{\leftmark}
\end{mdframed}%
\fancyfoot[C]{\thepage}
}
\pagestyle{fancy}

\usepackage{lipsum}

\begin{document}

\section{test}
\lipsum[1-10]

\end{document}

在此处输入图片描述

答案2

我会使用 TikZ 和一个不会影响标题中其他排版材料的环境。可以通过环境实现pgfinterruptboundingbox,然后对象相对于周围排版材料的宽度为 0 pt,高度为 0 pt。我附上一个例子作为起点。

编辑:接下来,我将其全部包裹在scope环境中,以将其全部移动到纸张的左边距。我将\textwidth其改为两次\paperwidth。我通常使用 TikZ 提供的绝对定位,好吧,我希望给scope一个机会。

\documentclass[a4paper]{article}
\usepackage{lipsum}
\usepackage{xcolor,tikz}
\usepackage{fancyhdr}\pagestyle{fancy}\fancyhf{}
\renewcommand{\headrulewidth}{0.0pt}
\def\mysquare{1cm}
\colorlet{myblue}{blue}
\fancyhead[L]{%
\begin{tikzpicture}[inner sep=0pt, outer sep=0pt]
\begin{scope}[xshift=-1in-\hoffset-\oddsidemargin]
\begin{pgfinterruptboundingbox}
\shade[fill=yellow, anchor=west, left color=myblue, right color=myblue!10, xshift=\mysquare] (0,0) rectangle (\paperwidth-\mysquare,\mysquare);
\node[minimum width=\mysquare, minimum height=\mysquare, draw, align=center, font=\bfseries\color{white}, fill=myblue, anchor=south west] at (0,0) (leftside) {MM\\O};
\node[font=\bfseries, anchor=east] at (\paperwidth,0.5\mysquare) {\leftmark\hspace{3mm}\thesection\hspace*{6mm}};
\end{pgfinterruptboundingbox}%
\end{scope}
\end{tikzpicture}%
}% End of \fancyhead...
\begin{document}
\renewcommand{\sectionmark}[1]{%
\markboth{#1}{}}
\section{Enfriamiento simulado}
\lipsum[2]
\end{document}

在此处输入图片描述 在此处输入图片描述

相关内容