The problem seems to be that listings
expects a constant line height, and that \vdots
just takes up too much vertical space. One fix is to redefine \vdots
so that it takes up less vertical space:
\renewcommand\vdots{%
\vbox{\baselineskip3pt\lineskiplimit0pt\kern1pt\hbox{.}\hbox{.}\hbox{.}\kern-1pt}}
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}
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.
Best Answer
You can use the very powerful
tcolorbox
package, so the background is colored on a global basis, rather than line by line:I have also provided some commands for adjusting the horizontal position of the boxes.