我正在尝试用 Latex 编写包含方程式的伪代码。我的 MWE 如下
'\begin{algorithm}
\caption{Fuzzy c-means clustering algorithm}
\begin{algorithmic}[1]
\State Choose primary centroids $v_{k}$
\State Compute the membership degree of all feature vectors in all clusters
\begin{equation}
u_{ki} = \frac{1}{ \sum_{j=1}^C ( \frac{D^{2}(x_{i} - v_{k})}{D^{2}(x_{i} - v_{j})})^\frac{2}
{m-1}}
\label{updateU}\\
\end{equation}
\end{algorithmic}
\end{algorithm}
我该如何解决?
答案1
假设您正在使用包algorithm
和algorithmicx
,则以下工作有效(只是删除\\
)。
\documentclass{article}
\usepackage{algorithm}
\usepackage{algorithmicx}
\begin{document}
\begin{algorithm}
\caption{Fuzzy c-means clustering algorithm}
\begin{algorithmic}[1]
\State Choose primary centroids $v_{k}$
\State Compute the membership degree of all feature vectors in all clusters
\begin{equation}
u_{ki} = \frac{1}{ \sum_{j=1}^C ( \frac{D^{2}(x_{i} - v_{k})}{D^{2}(x_{i} - v_{j})})^\frac{2}
{m-1}}
\label{updateU} % removed \\
\end{equation}
\end{algorithmic}
\end{algorithm}
\end{document}
(顺便说一句,如果您提供的 MWE 是可编译的,那就最好了,也就是说,可以将其复制粘贴到编辑器中并直接编译它;您很少(从不?)应该回避包含documentclass
MWE 所需的内容、包等。)祝一切顺利!