![algorithm2e 中的 Tikz 节点阻止文件编译](https://linux22.com/image/332735/algorithm2e%20%E4%B8%AD%E7%9A%84%20Tikz%20%E8%8A%82%E7%82%B9%E9%98%BB%E6%AD%A2%E6%96%87%E4%BB%B6%E7%BC%96%E8%AF%91.png)
由于某种原因,我找不到哪里出错了。我在 algorithm2e 环境中放置了一个 tikz 节点,现在文件无法编译。我收到错误,Missing } inserted.
我看不到我缺少“}”的地方请帮助我编译文件。谢谢。
以下是代码:
\documentclass{article}
\usepackage{amsmath, amsfonts, amssymb, amsthm, bm}
\usepackage{commath}
\usepackage{xcolor}
\usepackage[most]{tcolorbox}
\usepackage{tikz}
\usetikzlibrary{backgrounds}
\usetikzlibrary{tikzmark,calc,,arrows,shapes,decorations.pathreplacing}
\tikzset{every picture/.style={remember picture}}
\usepackage[linesnumbered,ruled,vlined]{algorithm2e}
\newcommand\mycommfont[1]{\footnotesize\ttfamily\textcolor{blue}{#1}}
\SetCommentSty{mycommfont}
\definecolor{mybluei}{RGB}{0,173,239}
\begin{document}
\colorbox{mybluei!05}{\color{black}
\begin{minipage}{\textwidth}
\SetAlgoLined
\SetNlSty{textbf}{}{:}
\begin{algorithm}[H]
\begin{align*}
Q_{s} &= \left[ q_{1}, q_{2},...,q_{M-1}\right]
\intertext{Then}
\tikz{\node{$E_{s} &= \subnode(d4){$X$}\subnode(d5){$Q_{s}$} \hspace{1.5cm} \Rightarrow\rho\times(M-1)$};}
\end{align*}
\begin{tikzpicture}[remember picture,overlay]{
\draw[blue,thick,->] (d4) to [in=90,out=245] + (225:2.7cm) node[anchor=north,text = black] {current estimate};
\draw[blue,thick,->] (d5) to [in=90,out=265] +(235:1.8cm) node[anchor=north,text = black] {previous estimate};}
\end{tikzpicture}
\end{algorithm}
\end{minipage}}
\end{document}
答案1
几点:align
无法看到&
TikZ 内部的node
。放在图片E_s &=
外面\tikz
。\subnode
应该用作\subnode{d4}{$X$}
,而不是\subnode(d4){$X$}
(注意括号)。并且您需要将 的基线设置tikzpicture
为有用的内容。
\documentclass{article}
\usepackage{amsmath, amsfonts, amssymb, amsthm, bm}
\usepackage{commath}
\usepackage[most]{tcolorbox}
\usepackage{tikz}
\usetikzlibrary{backgrounds}
\usetikzlibrary{tikzmark,calc,,arrows,shapes,decorations.pathreplacing}
\tikzset{every picture/.style={remember picture}}
\usepackage[linesnumbered,ruled,vlined]{algorithm2e}
\newcommand\mycommfont[1]{\footnotesize\ttfamily\textcolor{blue}{#1}}
\SetCommentSty{mycommfont}
\definecolor{mybluei}{RGB}{0,173,239}
\begin{document}
\begin{minipage}{\textwidth}
\SetAlgoLined
\SetNlSty{textbf}{}{:}
\begin{algorithm}[H]
\begin{align*}
Q_{s} &= \left[ q_{1}, q_{2},...,q_{M-1}\right]
\intertext{Then}
E_{s} &= \tikz[baseline=(a.base)]\node(a){\subnode{d4}{$X$}\subnode{d5}{$Q_{s}$} \hspace{1.5cm} $\Rightarrow\rho\times(M-1)$};
\end{align*}
\begin{tikzpicture}[remember picture,overlay]{
\draw[blue,thick,->] (d4) to [in=90,out=245] + (225:2.7cm) node[anchor=north,text = black] {current estimate};
\draw[blue,thick,->] (d5) to [in=90,out=265] +(235:1.8cm) node[anchor=north,text = black] {previous estimate};}
\end{tikzpicture}
\end{algorithm}
\end{minipage}
\end{document}