gpt4 book ai didi

latex - 将列表放入 tikzpicture

转载 作者:行者123 更新时间:2023-12-04 21:10:18 24 4
gpt4 key购买 nike

我使用以下代码为方程创建一个框。它使用 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}

enter image description here

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

关于latex - 将列表放入 tikzpicture,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36372576/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com