
パッケージによって記述された疑似コードをノードalgpseudocode
内に配置するにはどうすればよいですかtikz
? (コードを装飾するだけでなく、グラフ内で使用したい)
ムウェ
\documentclass{article}
\usepackage{tikz}
\usepackage{algpseudocode}
\begin{document}
\begin{tikzpicture}
\node[draw, rounded corners] {%
\begin{algorithmic}
\If{$\mathrm{n}=\mathrm{np}$}
\State Have fun
\EndIf
\end{algorithmic}%
};
\end{tikzpicture}
\end{document}
結果
次のようなエラーが多数発生します:
何かが間違っています。おそらく、\item が欠落しているのでしょう。
答え1
環境algorithmic
はボックス内に配置することができませんが、 内に配置することはできますminipage
。テキストを擬似コード フラグメントの自然な幅に合わせたいので、varwidth
を直接使用するのではなく、 パッケージを使用しましたminipage
。
\documentclass{article}
\usepackage{tikz}
\usepackage{varwidth}
\usepackage{algpseudocode}
\begin{document}
\begin{tikzpicture}
\node[draw, rounded corners] {%
\begin{varwidth}{\linewidth}
\begin{algorithmic}
\If{$\mathrm{n}=\mathrm{np}$}
\State Have fun
\EndIf
\end{algorithmic}%
\end{varwidth}
%
};
\end{tikzpicture}
\end{document}