我是 Latex 新手,当我尝试创建文档时,出现以下部分。但它不起作用,并给出
$ 缺失
错误。
\textbf{Algorithm 1}\\
\textit{ld \Leftarrow (ld_1,ld_2,ld_3,...,ld_N)} \\
\textit{D \Leftarrow ld_1 + ld_2 + ld_3+...+ld_N } \\
\textit{P$_a$ \Leftarrow available power} \\
\textbf{for } i $ = 1 $ to N \textbf{ do}\\
\textit{la$_*i$ \Leftarrow P$_a$ \div D \times ld$_i$}\\
\textit{\textbf{end for}}\\
la$_*$ represents the allocated power to each load and its calculated using\\
\textit{la$_*$ = la$_*1$,la$_*2$,la$_*3$...,la$_*N$}\\
\textit{la$_*1$+la$_*2$+la$_*3$+ ...+la$_*N$}
我在这里遗漏了什么?
提前致谢。
答案1
它缺少$
。\leftarrow
必须被$
、 以及包围_
。您应该使用类似 的包algorithmicx
展示你的算法。\\
不应该用来换行。这可行,但远非清晰易读:
\textbf{Algorithm 1}\\
\textit{ld $\Leftarrow (ld_1,ld_2,ld_3,...,ld_N)$} \\
\textit{D$ \Leftarrow ld_1 + ld_2 + ld_3+...+ld_N$} \\
\textit{P$_a$ $\Leftarrow$ available power} \\
\textbf{for } $i = 1$ to N \textbf{ do}\\
\textit{la$_*i$ $\Leftarrow P_a \div D \times ld_i$}\\
\textit{\textbf{end for}}\\
la$_*$ represents the allocated power to each load and its calculated using\\
\textit{la$_*$ = la$_*1$,la$_*2$,la$_*3$...,la$_*N$}\\
\textit{la$_*1$+la$_*2$+la$_*3$+ ...+la$_*N$}