[Tex/LaTex] background color of colorbox doesnt fill enclosing framebox entirely

boxescolor

I am using a colorbox (that contains a parbox) inside a framebox.
Inside the parbox there is an itemize environment

I need some paddding around the text so I put fboxsep for the colorbox to 6pt

However I cant seem to get the background color to fill the framebox entirely even though I set the fboxsep of the framebox to 0pt.
There is always space remaining at the left and right hand side as can be seen from the example.

\documentclass[letterpaper,12pt]{article}
\usepackage[usenames,dvipsnames]{xcolor}
\begin{document}

{\setlength{\fboxsep}{0pt}
\centering  
\framebox{
\setlength{\fboxsep}{6pt}
 \colorbox{red}{\parbox{\textwidth}
{\centering 

 Some text text text

\begin{itemize}
\item xxxxxxxxxxxxxxxxxxxxxxxxxxx
\item yyyyyyyyyyyyyyyyyyyyyyyyyyy
\item zzzzzzzzzzzzzzzzzzzzzzzzzzz
\end{itemize}
 \par}}
}
\par}

\end{document}

Any ideas ?

enter image description here

Best Answer

There were some spurious blank spaces at the end of some lines (I killed them using %); also, you need to correct the width for the \parbox to take into account the padding of the colorbox and the width of the rules of the \framebox:

\documentclass[letterpaper,12pt]{article}
\usepackage[usenames,dvipsnames]{xcolor}
\begin{document}

{\setlength{\fboxsep}{0pt}
\centering  
\framebox{%
\setlength{\fboxsep}{6pt}%
 \colorbox{red}{\parbox{\dimexpr\textwidth-2\fboxsep-2\fboxrule\relax}%
{\centering 

 Some text text text

\begin{itemize}
\item xxxxxxxxxxxxxxxxxxxxxxxxxxx
\item yyyyyyyyyyyyyyyyyyyyyyyyyyy
\item zzzzzzzzzzzzzzzzzzzzzzzzzzz
\end{itemize}
 \par}}%
}
\par}

\end{document}

enter image description here

You can use a single \fcolorbox instead of a \framebox and a \colorbox:

\documentclass[letterpaper,12pt]{article}
\usepackage[usenames,dvipsnames]{xcolor}

\begin{document}

{\par\noindent  
\setlength{\fboxsep}{6pt}%
\fcolorbox{black}{red}{\parbox{\dimexpr\textwidth-2\fboxsep-2\fboxrule\relax}%
{\centering 
 Some text text text
\begin{itemize}
\item xxxxxxxxxxxxxxxxxxxxxxxxxxx
\item yyyyyyyyyyyyyyyyyyyyyyyyyyy
\item zzzzzzzzzzzzzzzzzzzzzzzzzzz
\end{itemize}
}}%
\par
}

\end{document}

Or, even simpler, use mdframed or tcolorbox:

\documentclass[letterpaper,12pt]{article}
\usepackage[usenames,dvipsnames]{xcolor}
\usepackage{mdframed}

\begin{document}


\begin{mdframed}[backgroundcolor=red]
 Some text text text
\begin{itemize}
\item xxxxxxxxxxxxxxxxxxxxxxxxxxx
\item yyyyyyyyyyyyyyyyyyyyyyyyyyy
\item zzzzzzzzzzzzzzzzzzzzzzzzzzz
\end{itemize}
\end{mdframed}

\end{document}

or

\documentclass[letterpaper,12pt]{article}
\usepackage[usenames,dvipsnames]{xcolor}
\usepackage{tcolorbox}

\begin{document}


\begin{tcolorbox}[colback=red,arc=0pt,outer arc=0pt,colframe=black,boxrule=0.4pt]
 Some text text text
\begin{itemize}
\item xxxxxxxxxxxxxxxxxxxxxxxxxxx
\item yyyyyyyyyyyyyyyyyyyyyyyyyyy
\item zzzzzzzzzzzzzzzzzzzzzzzzzzz
\end{itemize}
\end{tcolorbox}

\end{document}

With both package you can define a dedicated box if this is going to be used multiple times.