
Al escribir un algoritmo usando la sintaxis de Latex, encontré un problema de sangría en el que los procedimientos comenzaban en un lugar y terminaban en otro. Parte del código:
\documentclass{article}
\usepackage{amsmath}
\usepackage{algorithm}
\usepackage{algpseudocode}
\makeatletter
\def\BState{\State\hskip-\ALG@thistlm}
\makeatother
\begin{document}
\begin{algorithm}
\caption{Test}\label{euclid}
\begin{algorithmic}[1]
\State $\textit{currentS} \gets \textit{initialS}$
\State $\textit{bestS} \gets \textit{currentS}$
\State $\textit{listTest} \gets \left[ \right]$
\While{$fitness(bestS) < 0$}{
\State $\textit{bestC} \gets \textit{null}$
\For {($\textit{ca} \in \textit{currentS.get})}${
\If{($\neg\textit{listTest.contains(c)})$}{
\EndIf}
\EndFor}
\EndWhile}
\State \Return $\textit{bestSolution}$
\end{algorithmic}
\end{algorithm}
\end{document}
Respuesta1
Estás haciendo un mal uso de la herramienta: la sintaxis \While
es
\While {<condition>}
...
\EndWhile
sin llaves alrededor del contenido del bucle.
Código completo (agregué un \State
en el interior \If
); Tenga en cuenta también que \mathit
es preferible a \textit
. Para la matriz nula cambié \left[\right]
a [\,]
.
\documentclass{article}
\usepackage{amsmath}
\usepackage{algorithm}
\usepackage{algpseudocode}
\makeatletter
\def\BState{\State\hskip-\ALG@thistlm}
\makeatother
\begin{document}
\begin{algorithm}
\caption{Test}\label{euclid}
\begin{algorithmic}[1]
\State $\mathit{currentS} \gets \mathit{initialS}$
\State $\mathit{bestS} \gets \mathit{currentS}$
\State $\mathit{listTest} \gets [\,]$
\While{$\mathit{fitness}(\mathit{bestS}) < 0$}
\State $\mathit{bestC} \gets \mathit{null}$
\For {($\mathit{ca} \in \mathit{currentS.get})}$
\If{($\neg\mathit{listTest.contains(c)})$}
\State do something
\EndIf
\EndFor
\EndWhile
\State \Return $\mathit{bestSolution}$
\end{algorithmic}
\end{algorithm}
\end{document}