[Tex/LaTex] graphic in tcblisting

listingsshowexpltcolorbox

I'm using the package tcolorbox to create a file with examples Latex, I have reviewed the options tcblisting environment and use these:

  • text outside listing
  • listing outside text
  • listing above text
  • text above listing

But sometimes I want to show the example does not fit as I desire, and this comes my question: can you use an option to add a graphic instead of formatted text?. Something like "graphic" option from package "showexpl".
regards,
Pablo
EDIT: Like this
enter image description here

Best Answer

Starting with tcolorbox version 2.71 (2014/02/21), all missing comment outside listing e.a. options are implemented. A comment is considered as quite anything, especially a picture. For pictures, there is the new option image comment which simply sets a picture as comment.

A comment outside a tcolorbox (left/right/below/above) is always considered as the lower part of the box content. Thus, in the following example, center lower is centering a picture which is actually above the listing.

\documentclass{article}
\usepackage[most]{tcolorbox}

\newtcblisting{mylisting}[1]{%
  colback=red!5!white,colframe=red!75!black,
  image comment={width=2.5cm}{example-image-a.pdf},
  #1}

\begin{document}


\section{listing outside image}

\begin{mylisting}{listing outside comment,righthand width=2.5cm}
\Large\TeX{} \LaTeX{}\par
\LaTeX{} \TeX{}
\end{mylisting}

\section{image outside listing}

\begin{mylisting}{comment outside listing,lefthand width=2.5cm}
\Large\TeX{} \LaTeX{}\par
\LaTeX{} \TeX{}
\end{mylisting}

\section{listing above image}

\begin{mylisting}{listing above comment,center lower}
\Large\TeX{} \LaTeX{}\par
\LaTeX{} \TeX{}
\end{mylisting}

\section{image above listing}

\begin{mylisting}{comment above listing,center lower}
\Large\TeX{} \LaTeX{}\par
\LaTeX{} \TeX{}
\end{mylisting}

\clearpage
\section{listing side image}

\begin{mylisting}{listing side comment,lower separated=false,
  righthand width=2.5cm}
\Large\TeX{} \LaTeX{}\par
\LaTeX{} \TeX{}
\end{mylisting}


\section{image side listing}

\begin{mylisting}{comment side listing,lower separated=false,
  lefthand width=2.5cm}
\Large\TeX{} \LaTeX{}\par
\LaTeX{} \TeX{}
\end{mylisting}


\section{listing and image}

\begin{mylisting}{listing and comment,bicolor,colbacklower=white,center lower}
\Large\TeX{} \LaTeX{}\par
\LaTeX{} \TeX{}
\end{mylisting}


\section{image and listing}

\begin{mylisting}{comment and listing,bicolor,colback=white,
  colbacklower=red!5!white,center upper}
\Large\TeX{} \LaTeX{}\par
\LaTeX{} \TeX{}
\end{mylisting}

\end{document}

enter image description here enter image description here

Related Question