我想在页眉旁边画一个蓝色框,但蓝色框应该位于页边距中,而不是页眉本身的一部分。在实际文档中,页边距设置为geometry
。
\documentclass[a4paper,12pt,ngerman]{article}
\usepackage{babel}
\usepackage{tikz}
\usepackage{fancyhdr}
\usepackage{color}
%\usepackage\[a4paper,%showframe,
%left= 2.5cm, % linker Rand
%right= 1.99cm, % rechter Rand
%top= 2.5cm, % oberer Rand
%bottom= 2cm, % unterer Rand
%\]
%{geometry}
\newsavebox\myLogoBox
\savebox\myLogoBox{%
\begin{tikzpicture}
\fill\[fill=blue\] (1mm,2mm) rectangle +(2cm,7mm);
\end{tikzpicture}%
}
\newcommand{\insertlogo}{\usebox{\myLogoBox}}%
\setlength\headheight{ 1.5 cm}
\pagestyle{fancy}
\fancyhf{}
\lhead{\insertlogo~\LARGE{\textbf{Lebenslauf}}}
\begin{document}
A
\end{document}
答案1
将蓝色框放在宽度为的框内0pt
:
\lhead{\makebox[0pt][r]{\insertlogo~}\LARGE{\textbf{Lebenslauf}}}
完整代码:
\documentclass[a4paper,12pt,ngerman]{article}
\usepackage{babel}
\usepackage{tikz}
\usepackage{fancyhdr}
\usepackage{color}
\usepackage[a4paper,%showframe,
left= 2.5cm, % linker Rand
right= 1.99cm, % rechter Rand
top= 2.5cm, % oberer Rand
bottom= 2cm, % unterer Rand
]
{geometry}
\newsavebox\myLogoBox
\savebox\myLogoBox{%
\begin{tikzpicture}
\fill[fill=blue] (1mm,2mm) rectangle +(2cm,7mm);
\end{tikzpicture}%
}
\newcommand{\insertlogo}{\usebox{\myLogoBox}}%
\setlength\headheight{ 1.5 cm}
\pagestyle{fancy}
\fancyhf{}
\lhead{\makebox[0pt][r]{\insertlogo~}\LARGE\textbf{Lebenslauf}}
\begin{document}
A
\end{document}
答案2
Harish Kumar 的变种answer
,但现在该框从左边距一直延伸到与文本区域的距离由\LogoSep
(default= ) 控制:10pt
\documentclass[a4paper,12pt,ngerman]{article}
\usepackage{babel}
\usepackage{tikzpagenodes}
\usepackage{fancyhdr}
\usetikzlibrary{calc}
\usepackage[a4paper,%showframe,
left= 2.5cm, % linker Rand
right= 1.99cm, % rechter Rand
top= 2.5cm, % oberer Rand
bottom= 2cm, % unterer Rand
]
{geometry}
% Separation between blue box and header
\newlength\LogoSep
\setlength\LogoSep{10pt}
\newsavebox\myLogoBox
\savebox\myLogoBox{%
\begin{tikzpicture}
\fill[fill=blue]
let
\p1=(current page.west),
\p2=(current page text area.west)
in
(\x1,0mm) rectangle ++(\x2-\x1-\LogoSep,5mm);
\end{tikzpicture}%
}
\newcommand{\insertlogo}{\usebox{\myLogoBox}}%
\setlength\headheight{1.5cm}
\pagestyle{fancy}
\fancyhf{}
\fancyhead[L]{\makebox[0pt][r]{\insertlogo\hspace{\LogoSep}}\LARGE\textbf{Lebenslauf}}
\begin{document}
Test text
\end{document}
结果:
评论
字体开关
\LARGE
没有参数;{\LARGE text}
如果需要,请在离开组之前将它们用作(仅当需要分组时才使用括号)并可能结束段落。我从旧
\lhead{...}
语法转换为现代\fancyhead[L]{...}
语法。