Graphics, Figures & TablesColored Box with Width of Paper

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
gmsotavio
Posts: 10
Joined: Sun Aug 12, 2012 1:41 am

Colored Box with Width of Paper

Post by gmsotavio »

Hello,

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 951 times
Otavio Augusto

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

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

Post by localghost »

Please show what you have tried so far in form of a self-contained and minimal example.


Thorsten
gmsotavio
Posts: 10
Joined: Sun Aug 12, 2012 1:41 am

Re: Colored Box with Width of Paper

Post by gmsotavio »

localghost, the attached file, was done using a basic office suite, like LibreOffice. I do not tried nothing because I dont have any idea how to do it.
Otavio Augusto
User avatar
Stefan Kottwitz
Site Admin
Posts: 10330
Joined: Mon Mar 10, 2008 9:44 pm

Colored Box with Width of Paper

Post by Stefan Kottwitz »

It could be done using atbegshi, eso-pic and similar packages with a picture environment.

I prefer TikZ for such things. It provides a 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}
page.png
page.png (5.81 KiB) Viewed 10200 times
Stefan
LaTeX.org admin
gmsotavio
Posts: 10
Joined: Sun Aug 12, 2012 1:41 am

Re: Colored Box with Width of Paper

Post by gmsotavio »

Stefan, I performed a simple adaptation in the Latex Code which you posted, for my purposes and it works perfectly. So useful! Thanks a lot Stefan!!
Otavio Augusto
Post Reply