我想制作一条横跨整个页面的彩色带,其中包含联系信息。我正在尝试使用颜色包和\colorbox
。我似乎无法让彩色带从页面的左边缘开始。这个包可以做到这一点吗?
以下是我尝试过的一个例子:
\documentclass[letterpaper, 12pt]{scrartcl}
\usepackage{color}
\begin{document}
\colorbox{cyan}{ \parbox{8.5in}{test} }
\end{document}
答案1
\oddsidemargin+1in
除了考虑之外,您还必须移动左边的盒子\fboxsep
。
\documentclass[letterpaper, 12pt]{scrartcl}
\usepackage{color}
\usepackage{lipsum}
\begin{document}
\noindent\makebox[\textwidth][l]{%
\hspace{-\dimexpr\oddsidemargin+1in}%
\colorbox{cyan}{%
\parbox{\dimexpr\paperwidth-2\fboxsep}{\lipsum[3]}%
}%
}
\end{document}
答案2
以下代码\insertcolorband{<colour>}
使用 colour 插入页面宽度的颜色带<colour>
。使用以下代码将颜色带插入背景中:eso-pic
并且第一次需要至少进行 2 次编译(或者\insertcolorband
宏的垂直位置发生任何变化):
\documentclass{article}
\usepackage{xcolor,eso-pic}
\usepackage[savepos]{zref}
\newcounter{colorband}
\newcommand{\insertcolorband}[1]{%
\leavevmode\stepcounter{colorband}% New \insertcolorband
\zsaveposy{cb-\thecolorband}% Mark y-position
\edef\x{% Identify y-coordinate for storage
\noexpand\AddToShipoutPictureBG*{% Place band in background of current page
\noexpand\AtPageLowerLeft{% Marked from the lower-left corner of the page
\noexpand\color{#1}% Band colour
\noexpand\rule[\dimexpr\zposy{cb-\thecolorband}sp-.3\baselineskip]{\paperwidth}{\baselineskip}% Horizontal rule of height \baselineskip
}%
}}\x% Add content to background
}
\begin{document}
\sloppy% Just for this example
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus eu vulputate lacus.
Quisque nec leo non augue venenatis maximus. Maecenas vitae mollis est. Proin tempus
sem posuere, varius diam vel, sagittis leo. Vivamus eget mauris et lectus egestas aliquam.
Nulla ipsum nisi, tempor non cursus faucibus, pellentesque eu ligula. Etiam elementum
nisl sed sapien condimentum rhoncus. Quisque blandit eget sem ut mattis. Curabitur varius
elementum dolor, eget bibendum risus. Nullam at libero ut risus tincidunt pellentesque.
\insertcolorband{cyan}%
test
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus eu vulputate lacus.
Quisque nec leo non augue venenatis maximus. Maecenas vitae mollis est. Proin tempus
sem posuere, varius diam vel, sagittis leo. Vivamus eget mauris et lectus egestas aliquam.
Nulla ipsum nisi, tempor non cursus faucibus, pellentesque eu ligula. Etiam elementum
nisl sed sapien condimentum rhoncus. Quisque blandit eget sem ut mattis. Curabitur varius
elementum dolor, eget bibendum risus. Nullam at libero ut risus tincidunt pellentesque.
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus eu vulputate lacus.
Quisque nec leo non augue venenatis maximus. Maecenas vitae mollis est. Proin tempus
sem posuere, varius diam vel, sagittis leo. Vivamus eget mauris et lectus egestas aliquam.
\insertcolorband{green!20}%
Nulla ipsum nisi, tempor non cursus faucibus, pellentesque eu ligula. Etiam elementum
nisl sed sapien condimentum rhoncus. Quisque blandit eget sem ut mattis. Curabitur varius
elementum dolor, eget bibendum risus. Nullam at libero ut risus tincidunt pellentesque.
\end{document}
答案3
您需要考虑颜色框两端的 fboxsep 填充:
\documentclass[letterpaper, 12pt]{scrartcl}
\usepackage{color}
\begin{document}
text block
{\noindent\colorbox{cyan}{\makebox[\dimexpr\linewidth-2\fboxsep\relax]{test}}}
page
{\noindent\hspace*{\dimexpr-\oddsidemargin-1in\relax}%
\colorbox{cyan}{\makebox[\dimexpr\paperwidth-2\fboxsep\relax]{test}}%
\hspace*{-\paperwidth}}
\end{document}