2

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

2

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.

  • thx for pointing me to tcolorbox! I am a bit at loss understanding your first solution. All the tex macros like \dimexpr are quite obscure for me... – Mathias Vanwolleghem May 3 '14 at 19:05
  • 1
    @MathiasVanwolleghem You're welcome. \dimexpr is an e-TeX macro that allows simple arithmetic operations with lengths; \dimexpr\textwidth-2\fboxsep-2\fboxrule\relax simply subtracts twice the value of \fboxsep (the padding between the box and its contents) and twice \fboxrule (the thickness of rules) from \textwidth, to get the correct width. – Gonzalo Medina May 3 '14 at 19:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.