我定义了以下命令\recomm
来打印一个带有分离主体和标题的框:
\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}%
}
当使用简单的输入时,它可以正常工作并打印出一个漂亮的框:
\recomm{Title}{%
Some content in the first part
}{%
Some content in the second part
}
但是,当我尝试使用环境插入代码列表时lstlisting
,出现各种错误:
\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 }
我尝试使用\newenvironment
,但它只允许单个环境,而我需要两个环境(图片的第一部分和第二部分)。有什么推荐的方法可以很好地解决这个问题?
(我想避免使用 tcolorbox,因为我必须使用一个非常不完整的 texlive 环境,其中不包含该包及其许多依赖项。)
最小不起作用的示例:
\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}