# Insert pictures inside a color box spanning the whole page width

This question led to a new package:
clrstrip

this is a very noob asking, as I do not use any graphics in LaTeX usually... I want to put pictures inside a color box : something like that

with a fullwidth color box. Should I use - mdframed package ? - Tickz package ? - an includegraphics command : for instance \colorbox{white}{\includegraphics{my-figure}} ?

Thanks for any help.

• TikZ could certainly handle it, but is a bit complicated. It would be even more useful if you were planning on overlapping the images. – John Kormylo Jun 1 '18 at 18:08

This question led to a new package:
clrstrip

With xcolor and graphicx:

\documentclass[]{article}

\usepackage{xcolor}
\usepackage[]{graphicx}
\usepackage{duckuments}
\newcommand*\picandtext[2]{\begin{tabular}{@{}c@{}}#1\\#2\end{tabular}}

\begin{document}
\noindent
\colorbox{blue!25}
{%
\begin{minipage}[]{\dimexpr\textwidth-2\fboxsep\relax}%
\vspace*{1cm}%
\mbox{}\hfill
\picandtext{\includegraphics[width=.2\textwidth]{example-image-duck}}
{Some text}\hfill
\picandtext{\includegraphics[width=.2\textwidth]{example-image-duck}}
{Some text}\hfill
\picandtext{\includegraphics[width=.2\textwidth]{example-image-duck}}
{Some text}%
\hfill\mbox{}
\vspace*{1cm}%
\end{minipage}%
}
\medskip

\blindduck
\end{document}


If you want to span the full width of the page:

\documentclass[]{article}

\usepackage{xcolor}
\usepackage[]{graphicx}
\usepackage{duckuments}
\usepackage{environ}

\newcommand*\picandtext[2]{\begin{tabular}{@{}c@{}}#1\\#2\end{tabular}}

\makeatletter
\newlength\colorstripTempDim
\NewEnviron{colorstrip}[2][]
{%
\par
\medskip
\noindent
\colorstripTempDim\textwidth
\hspace*{-\dimexpr\hoffset+1in+\oddsidemargin\relax}%
\rlap
{%
\if\relax\detokenize{#1}\relax
\expandafter\@firstoftwo
\else
\expandafter\@secondoftwo
\fi
{\colorbox{#2}}
{\colorbox[#1]{#2}}%
{%
\begin{minipage}[]{\dimexpr\paperwidth-2\fboxsep\relax}%
\vspace*{\medskipamount}%
\hspace*{\dimexpr\hoffset+1in+\oddsidemargin-\fboxsep\relax}%
\begin{minipage}{\colorstripTempDim}%
\BODY
\end{minipage}%
\medskip
\end{minipage}%
}%
}%
\par
\medskip
}
\makeatother

\begin{document}
\begin{colorstrip}{blue!25}
\vspace{1cm}%
\picandtext{\includegraphics[width=.3\textwidth]{example-image-duck}}
{Some text}%
\hfill
\picandtext{\includegraphics[width=.3\textwidth]{example-image-duck}}
{Some text}%
\hfill
\picandtext{\includegraphics[width=.3\textwidth]{example-image-duck}}
{Some text}%
\vspace{1cm}%
\end{colorstrip}

\blindduck

\begin{colorstrip}[gray]{.85}
\blindduck
\end{colorstrip}
text
\end{document}


A more robust approach could be to first save the content in a \vbox. This way stuff which relies on catcode changes (like \verb) would still work.

\documentclass[twoside]{article}

\usepackage{xcolor}

\makeatletter
\newsavebox\colorstrip@box
\newlength\colorstrip@height
\newlength\colorstrip@depth
\newlength\colorstrip@outerskip
\newlength\colorstrip@innerskip
\colorstrip@outerskip\medskipamount
\colorstrip@innerskip\colorstrip@outerskip
\newcommand*\colorstrip@oarg{}
\newcommand*\colorstrip@marg{}
\newenvironment{colorstrip}[2][]
{%
\def\colorstrip@oarg{#1}%
\def\colorstrip@marg{#2}%
\setbox\colorstrip@box\vbox\bgroup\noindent
}
{%
\egroup
\par
\vskip\colorstrip@outerskip
\noindent
\colorstrip@height\ht\colorstrip@box
\colorstrip@depth\dp\colorstrip@box
\begingroup
\if\relax\detokenize\expandafter{\colorstrip@oarg}\relax
\color{\colorstrip@marg}%
\else
\color[\colorstrip@oarg]{\colorstrip@marg}%
\fi
\rlap
{%
\hspace*{-\paperwidth}%
\vrule
width 2\paperwidth
height \colorstrip@height
depth \colorstrip@depth
}%
\endgroup
\usebox\colorstrip@box
\par
\vskip\colorstrip@outerskip
}
\makeatother

\usepackage{duckuments}

\begin{document}
\begin{colorstrip}{gray!25}
\blindduck[1]
\end{colorstrip}
\clearpage
\begin{colorstrip}{gray!25}
\blindduck[1]
\end{colorstrip}
\begin{colorstrip}{gray!25}
\begin{tabular}[b]{ll}
test & this\\
tabular & thingy
\end{tabular}
\end{colorstrip}
text outside
\end{document}

• Thanks a lot, @Skillmon ! OMG, this is exactly what I needed. There is nothing impossible for LaTeX ! Btw, I didn't know the duckuments package, lovely ;-) ! – Ratoune2008 Jun 1 '18 at 21:01
• @Ratoune2008 thanks (I wrote it) :) – Skillmon Jun 1 '18 at 21:01
• a LaTeX AND blind duck Great Master, you are ;-) – Ratoune2008 Jun 1 '18 at 21:04
• @Ratoune2008 sadly I don't know how to continue the plot. It should come out as a great journey for the underduckling, but I just don't know how to write on :( – Skillmon Jun 1 '18 at 21:06
• @Ratoune2008 oh, and I don't know how robust above solution is. I tested it only with article and with and without geometry. I hope it works well for you. – Skillmon Jun 1 '18 at 21:07

Just another approach using tcolorbox (MWE from Skillmon's post). It uses the raster library to provide a boxed raster which is styled separately from the rastered boxes. Image and text are upper and lower part of the inner boxes.

For the content to stay within the margins you have to adapt the left and right keys to your margins. You may add as many pictures as you like by modifying the number of raster columns.

\documentclass[]{article}

\usepackage[most]{tcolorbox}
\usepackage{graphicx}
\usepackage{duckuments}

\begin{document}
\noindent
\begin{tcboxedraster}[raster columns = 3, raster equal height, enhanced, frame hidden,
segmentation hidden, interior hidden, fontlower=\centering\color{white}\Huge\bfseries]{
frame hidden, boxrule=0pt, arc=0pt, left=20mm, right=20mm}
\begin{tcolorbox}
\includegraphics[width=\textwidth]{example-image-duck}
\tcblower
Some text
\end{tcolorbox}
\begin{tcolorbox}
\includegraphics[width=\textwidth]{example-image-duck}
\tcblower
Some text
\end{tcolorbox}
\begin{tcolorbox}
\includegraphics[width=\textwidth]{example-image-duck}
\tcblower
Some text
\end{tcolorbox}
\end{tcboxedraster}
\medskip

\blindduck
\end{document}