I defined the following command \recomm to print a box with a separated body and a title:
\newcommand{\recomm}[3]{
\vspace{0.5cm}
\noindent
\begin{tikzpicture}
\node [rectangle, inner sep=10pt] (box){%
\begin{minipage}{\dimexpr\linewidth-20pt-\pgflinewidth\relax}
#2
\end{minipage}
};
\node [rectangle, inner sep=10pt, fill=black!15, below right] (box2) at (box.south west){%
\begin{minipage}{\dimexpr\linewidth-20pt-\pgflinewidth\relax}
#3
\end{minipage}
};
\draw[draw=blue!75!black, very thick]
-- (box2.south west)
-- (box.north west)
-- (box.north east)
-- (box2.south east)
-- (box2.south west);
\node[above right, fill=blue!75!black, text=white, font=\bfseries] at (box.north west) {#1};
\end{tikzpicture}%
}
This works fine and prints a nice box when used with simple input:
\recomm{Title}{%
Some content in the first part
}{%
Some content in the second part
}
However, when I try to insert a code listing using the lstlisting environment, I'm getting all sorts of errors:
\recomm{Title}{%
Some content in the first part
}{%
Some content in the second part
\begin{lstlisting}
a=b
\end{lstlisting}
}
Argument of \lst@next has an extra }.
<inserted text>
\par
l.185 }
I tried using \newenvironment, but that allows only for a single environment where I need two (the first and second part of the picture). What is the recommended way to solve this nicely?
(I'd like to avoid tcolorbox, as I have to work with a very incomplete texlive environment where that package and many of its dependencies are not included.)
Minimal not working example:
\documentclass{article}
\usepackage{listings}
\usepackage{tikz}
\newcommand{\recomm}[2]{
\begin{tikzpicture}
\node [rectangle, inner sep=10pt] (box){%
\begin{minipage}{\dimexpr\linewidth-20pt-\pgflinewidth\relax}
#1
\end{minipage}
};
\node [rectangle, inner sep=10pt, fill=black!15, below right] (box2) at (box.south west){%
\begin{minipage}{\dimexpr\linewidth-20pt-\pgflinewidth\relax}
#2
\end{minipage}
};
}
\begin{document}
\recomm{%
Some content in the first part
}{%
Some content in the second part
\begin{lstlisting}
a=b
\end{lstlisting}
}
\end{document}

tcolorboxpackage which probably include what you are looking for. – daleif Dec 03 '19 at 11:07tcolorboxallows you to use all TikZ commands for your boxes usingoverlay. (The depicted box does not need that, it is very easy to reproduce it withtcolorboxwithoutoverlay, I think.) – Dec 03 '19 at 16:07tcolorbox. – janoliver Dec 03 '19 at 16:16tcolorboxdoes a lot of things behind the scenes, you'd basically have to redo them. Personally I would think it would be easier to fix the dependencies on your installation. – Dec 03 '19 at 17:14