我定義了以下命令\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}