我想要制作如下图所示的标题:
但我不知道如何强制颜色框在边缘溢出。我得到的最好的结果是:
我尝试使用\hspace
但它只移动文本:
\documentclass[a4paper,10pt]{article}
\usepackage[utf8x]{inputenc}
\usepackage[francais]{babel}
\usepackage{slantsc}
\usepackage{array}
\usepackage{multirow}
\pagestyle{empty}
\usepackage[T1]{fontenc}
\usepackage[default]{raleway}
\usepackage{amssymb}
\usepackage{layout}
\usepackage{fancyhdr}
\pagestyle{fancyplain}
\usepackage{xcolor}
\definecolor{myblue}{RGB}{0,100,200}
\fboxsep0pt
\setlength{\hoffset}{-26pt}
\setlength{\voffset}{-36pt}
\setlength{\oddsidemargin}{10pt}
\setlength{\topmargin}{10pt}
\setlength{\headheight}{100pt}
\setlength{\headwidth}{451pt}
\setlength{\headsep}{30pt}
\setlength{\textheight}{678pt}
\setlength{\textwidth}{451pt}
\setlength{\marginparsep}{10pt}
\setlength{\marginparwidth}{26pt}
\setlength{\footskip}{10pt}
\lhead{
\colorbox{myblue}{\parbox[b]{21cm}{\Huge Some text in my header.}}
}
\cfoot{}
\renewcommand{\headrulewidth}{0pt}
\begin{document}
\noindent Text of my document.
\end{document}
当我尝试时hspace
:
\colorbox{myblue}{\hspace{-50pt}\parbox[b]{21cm}{\Huge Some text in my header.}}
\hspace
我之前也尝试过,\colorbox
但是在这种情况下,没有效果。
答案1
您需要计算您在页面上的位置,以便正确地“跳转”(左/右)。为此,您可以使用以下方法保存当前左边距位置zref
的savepos
模块。
\documentclass{article}
\usepackage{fancyhdr,xcolor,zref-savepos}
\AtBeginDocument{\zsavepos{lmarginmark}}% Store left margin mark
\fancyhf{}
\makeatletter
\lhead{\leavevmode\rlap{%
\hspace*{-\zposx{lmarginmark}sp}% Adjust to left side of page
\colorbox{blue}{% blue box
\makebox[\dimexpr\pdfpagewidth-2\fboxsep][l]{% blue box width
\hspace*{\zposx{lmarginmark}sp}% Shift back to left margin
Some header}}}}
\makeatother
\pagestyle{fancy}
\begin{document}
\noindent Text of my document.
\end{document}
我已经包含了使用 的计算\fboxsep
,尽管你似乎将这些设置为0pt
答案2
如果您愿意,可以使用该tcolorbox
包来解决:
\documentclass[a4paper,10pt]{article}
\usepackage[utf8x]{inputenc}
\usepackage[francais]{babel}
\usepackage{slantsc}
\usepackage{array}
\usepackage{multirow}
\pagestyle{empty}
\usepackage[T1]{fontenc}
\usepackage[default]{raleway}
\usepackage{amssymb}
\usepackage{layout}
\usepackage{fancyhdr}
\pagestyle{fancyplain}
\usepackage{xcolor}
\definecolor{myblue}{RGB}{0,100,200}
\usepackage{tcolorbox}
\fboxsep0pt
\setlength{\hoffset}{-26pt}
\setlength{\voffset}{-36pt}
\setlength{\oddsidemargin}{10pt}
\setlength{\topmargin}{10pt}
\setlength{\headheight}{100pt}
\setlength{\headwidth}{451pt}
\setlength{\headsep}{30pt}
\setlength{\textheight}{678pt}
\setlength{\textwidth}{451pt}
\setlength{\marginparsep}{10pt}
\setlength{\marginparwidth}{26pt}
\setlength{\footskip}{10pt}
\lhead{%
\begin{tcolorbox}[size=tight,oversize,
sharp corners,
colback=myblue,
colframe=myblue,
left=56pt,
right=90pt,
fontupper=\Huge]
Some text in my header.
\end{tcolorbox}}
\cfoot{}
\renewcommand{\headrulewidth}{0pt}
\begin{document}
\noindent Text of my document.
\end{document}
只是为了好玩,我在文本上方和下方做了一个替代方案,并增加了渐变:
\documentclass[a4paper,10pt]{article}
\usepackage[utf8x]{inputenc}
\usepackage[francais]{babel}
\usepackage{slantsc}
\usepackage{array}
\usepackage{multirow}
\pagestyle{empty}
\usepackage[T1]{fontenc}
\usepackage[default]{raleway}
\usepackage{amssymb}
\usepackage{layout}
\usepackage{fancyhdr}
\pagestyle{fancyplain}
\usepackage{xcolor}
\definecolor{myblue}{RGB}{0,100,200}
\usepackage[skins]{tcolorbox}
\fboxsep0pt
\setlength{\hoffset}{-26pt}
\setlength{\voffset}{-36pt}
\setlength{\oddsidemargin}{10pt}
\setlength{\topmargin}{10pt}
\setlength{\headheight}{100pt}
\setlength{\headwidth}{451pt}
\setlength{\headsep}{30pt}
\setlength{\textheight}{678pt}
\setlength{\textwidth}{451pt}
\setlength{\marginparsep}{10pt}
\setlength{\marginparwidth}{26pt}
\setlength{\footskip}{10pt}
\lhead{%
\begin{tcolorbox}[size=tight,oversize,
sharp corners,
enhanced,
interior style={top color=myblue!50!white,bottom color=myblue},
colframe=myblue,
colupper=myblue!20!white,
left=56pt,
right=90pt,
bottom=4pt,
top=20pt,
fontupper=\Huge]
Some text in my header.
\end{tcolorbox}}
\cfoot{}
\renewcommand{\headrulewidth}{0pt}
\begin{document}
\noindent Text of my document.
\end{document}