我使用 latex 编写了此代码,但是,每次运行它时,最后都会出现 =0。请问我该如何停止显示“=0”。
下面是我的 Latex 伪代码:
\begin{algorithm}
\caption{Approximate Point in Triangulation Algorithm}
\begin{algorithmic}
\State S represents the set of anchors seen/reached by the free node.
\State $N_i$ represents the set of anchors seen/reached by each
\State anchor \in S. \newline
\setlength{\parindent}{5ex} \State For \mid$S$\mid number of anchors \{}
\State reachNodes = S\cap $N_i$)
\State { \}
\State sort reachNodes in descending order
\State select the three highest reachNodes
\State /* Centre of Gravity(COG) calculation */
\State Estimated Position $=$ COG of three highest reachNodes; \newline
\end{algorithmic}
\end{algorithm}
显示的内容如下:
答案1
您的代码包含多个 LaTeX 错误。如果您跳过它们,则输出将出现乱码。
在数学模式下排版数学,并注意再次终止数学模式。
缩进是算法环境处理的事情之一;
\For
在这种情况下,只需使用提供的命令。您不需要
\newline
s。行会自动换行。如果您不希望算法占据整个宽度,请将algorithmic
环境放入minipage
:\begin{minipage}{7cm}\begin{algorithmic}...\end{algorithmic}\end{minipage}
\documentclass{article}
\usepackage{algpseudocode,algorithm}
\begin{document}
\begin{algorithm}
\caption{Approximate Point in Triangulation Algorithm}
\begin{algorithmic}
\State $S$ represents the set of anchors seen/reached by the free node.
\State $N_i$ represents the set of anchors seen/reached by each anchor $i{}\in S$.
\For{each anchor $i\in S$}
\State $\mathit{reachNodes} = S\cap N_i$
\EndFor
\State sort $\mathit{reachNodes}$ in descending order
\State select the three highest nodes in $\mathit{reachNodes}$
\State /* Centre of Gravity (COG) calculation */
\State Estimated Position $=$ COG of three highest $\mathit{reachNodes}$;
\end{algorithmic}
\end{algorithm}
\end{document}