latex – 将列表放在tikzpicture中

我使用以下代码创建方程式框.它使用Tikz来创建盒子.

\documentclass[a4paper]{article}
\usepackage{tikz}
\usepackage{amsmath}
\usepackage{amsmath,amssymb}%      pour les maths
\usepackage{enumitem}
\usepackage{varwidth}
\usepackage{listings}
\usetikzlibrary{calc}

\newcommand{\mybox}[4][\textwidth-\pgfkeysvalueof{/pgf/inner xsep}-2mm]{%
\begin{figure}[!h]
\centering
\begin{tikzpicture}
\node[line width=.5mm, rounded corners, draw=#2, inner ysep=10pt, text width=#1, outer sep=0] (one) {\vspace*{15pt}\\\begin{varwidth}{\textwidth}#4\end{varwidth}};
\node[text=white,anchor=north east,align=center, minimum height=20pt] (two) at (one.north east) {#3 \hspace*{.5mm}};
\path[fill=#2] 
    (one.north west|-two.west) --
    ($(two.west)+(-1.5cm,0)$) 
    to[out=0,in=180] (two.south west) --
    (two.south east) [rounded corners] --
    (one.north east) -- 
    (one.north west) [sharp corners] -- cycle;
\node[text=white,anchor=north east,align=center, minimum height=20pt, text height=2ex] (three) at (one.north east) {#3 \hspace*{.5mm}};
\end{tikzpicture} 
\end{figure}
}

\begin{document}
\mybox{green!70!black}{The Caption}{
\begin{enumerate}
\item Show that\\
$\displaystyle D_2f(x,y) = \frac{\partial {}}{\partial{y}} \biggl( \int_0^xg_1 (t,0) \ dt + \int_0^y g_2(x,s) \ ds \biggr)$
\item prove that\\
$\displaystyle \biggl(\forall x\in\mathbb{R}  \biggr)\biggl(\forall y \in \mathbb{R} \biggr) x\neq y\, \text{ and } \, x+y \neq 2 \implies x^{2}-2x \neq y^2-2y$
\end{enumerate}

}
\end{document}

但是现在我想把列表放在盒子里面
当我把列表放在mbox中时,我收到了一个错误

\begin{lstlisting}[language=R]
fun1 <- function(data, data.frame, graph=TRUE, limit=20, ...) {
[omitted statements]
if (graph)
par(pch="*", ...)
[more omissions]
}
\end{lstlisting}

错误是

! Argument of \lst@next has an extra }.

最佳答案 您不能直接在参数内使用列表.您需要转义并正确准备逐字代码或将其存储在其他位置.有关更多信息,请参见
the listing manual的第6.1节.

将商家信息存储在一个框中

\begin{document}
\begin{lrbox}{\mylisting}
\begin{lstlisting}[language=R]
fun1 <- function(data, data.frame, graph=TRUE, limit=20, ...) {
[omitted statements]
if (graph)
par(pch="*", ...)
[more omissions]
}
\end{lstlisting}
\end{lrbox}

\mybox{green!70!black}{The Caption}{
  \usebox\mylisting
}
\end{document}

将列表存储在外部文件中

\lstinputlisting{external_file.R}

添加换行符^^ J

\begin{lstlisting}[language=R]^^J
fun1 <- function(data, data.frame, graph=TRUE, limit=20, ...) {^^J
[omitted statements]^^J
if (graph)^^J
par(pch="*", ...)^^J
[more omissions]^^J
}^^J
\end{lstlisting}

《latex – 将列表放在tikzpicture中》

注意:您可能需要为长长的第一行代码调整大小.

点赞