Graphics, Figures & Tables ⇒ Colored Box with Width of Paper
Colored Box with Width of Paper
I'm formatting an article, and I'd like a hint to draw a colored box on page, such as in the attached PDF file.
The colored box should cover the page, starting in the left edge and finishing in the right edge, independently of the text width size, in other words, a box which has the same width of the page.
Regards!
- Attachments
-
- example.pdf
- (110.31 KiB) Downloaded 952 times
NEW: TikZ book now 40% off at Amazon.com for a short time.
And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p
- localghost
- Site Moderator
- Posts: 9202
- Joined: Fri Feb 02, 2007 12:06 pm
Colored Box with Width of Paper
Board Rules
Avoidable Mistakes
¹ System: TeX Live 2025 (vanilla), TeXworks 0.6.10
Re: Colored Box with Width of Paper
- Stefan Kottwitz
- Site Admin
- Posts: 10335
- Joined: Mon Mar 10, 2008 9:44 pm
Colored Box with Width of Paper
atbegshi
, eso-pic
and similar packages with a picture
environment.I prefer

current page
node which we can use for drawing, using an overlay.Here's an example, which I posted some time ago on my blog, showing a similar thing, i.e. a rectangle over the page width with a title text. You could take this as a start any modify it. Just tell us if you have any question regarding it.
Compile at least twice to get the correct overlay position. Or click on Open in writeLaTeX above the code box.
Code: Select all
\documentclass[svgnames]{report}
\usepackage{tikz}
\usepackage{kpfonts}
\usepackage[explicit]{titlesec}
\newcommand*\chapterlabel{}
\titleformat{\chapter}
{\gdef\chapterlabel{}
\normalfont\sffamily\Huge\bfseries\scshape}
{\gdef\chapterlabel{\thechapter\ }}{0pt}
{\begin{tikzpicture}[remember picture,overlay]
\node[yshift=-3cm] at (current page.north west)
{\begin{tikzpicture}[remember picture, overlay]
\draw[fill=LightSkyBlue] (0,0) rectangle
(\paperwidth,3cm);
\node[anchor=east,xshift=.9\paperwidth,rectangle,
rounded corners=20pt,inner sep=11pt,
fill=MidnightBlue]
{\color{white}\chapterlabel#1};
\end{tikzpicture}
};
\end{tikzpicture}
}
\titlespacing*{\chapter}{0pt}{50pt}{-60pt}
\begin{document}
\tableofcontents
\chapter{Introduction}
Text
\chapter{Main}
\section{Section}
Text
\begin{thebibliography}{99}
\bibitem{Test} test reference
\end{thebibliography}
\end{document}