4

I want to create a centered colored parbox, but although I defined boarders using package geometry, the parbox has a greater margin left than right.

Thanks for help

\documentclass[a4paper,10pt]{article}
\usepackage[utf8]{inputenc}
\usepackage{color}
\usepackage[a4paper,top=1cm,left=2cm,right=2cm]{geometry}
\usepackage{graphicx}


\begin{document}

\definecolor{Blau1}{RGB}{0,97,175}
\definecolor{Blau2}{RGB}{86,189,218}
\definecolor{Blau3}{RGB}{212,239,252} % Define a custom color for the heading box

\colorbox{Blau3}{ % Creates a highlight behind the text using the previously-defined navy color

\parbox[t]{\linewidth}{ % Creates a box to take up the entire line width
\centering

\vspace*{14pt} % Whitespace above the text

\color{Blau1} \center{\textbf{\Large REPORT}} % Right-aligned heading text

\vspace*{14pt} % Whitespace below the text
}}


\end{document}
2
  • Welcome to TeX.SX!
    – Pier Paolo
    Dec 19, 2014 at 15:10
  • For your header line, you are already using the command \centering so there's no need to add the \center command. This should suffice: \color{Blau1}{\Large\textbf{REPORT}} Dec 19, 2014 at 15:49

1 Answer 1

4

You need to remove the indentation before the colorbox and the natural padding (maybe it's called in another way, I'm not sure) of the box. For the latter I used the calc package and set the length of the parbox to \textwidth-2\fboxsep, so textwidth minus the natural padding.

\documentclass[a4paper,10pt]{article}
\usepackage[utf8]{inputenc}
\usepackage{color}
\usepackage[a4paper,top=1cm,left=2cm,right=2cm]{geometry}
\usepackage{graphicx}
\usepackage{showframe}
\usepackage{calc}

\begin{document}

\definecolor{Blau1}{RGB}{0,97,175}
\definecolor{Blau2}{RGB}{86,189,218}
\definecolor{Blau3}{RGB}{212,239,252} 
\noindent\colorbox{Blau3}{% new code here
\parbox[t]{\textwidth-2\fboxsep}{% new code here
\centering
\vspace*{14pt} 
\color{Blau1} \center{\textbf{\Large REPORT}}
\vspace*{14pt}
}}
\end{document}

enter image description here

1
  • 1
    +1 (you beat me by a couple of seconds so I didn't post my answer:-) \fboxsep isn't called padding in the latex or color package docs, but that's what I normally call it these days using the (later) CSS terminology as people are more familiar with that. Dec 19, 2014 at 15:37

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .