
Latex 구문을 사용하여 알고리즘을 작성하는 동안 절차가 한 곳에서 시작되어 다른 곳에서 끝나는 들여쓰기 문제가 발생했습니다. 코드의 일부:
\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}
답변1
도구를 오용하고 있습니다. 구문은 다음과 \While
같습니다.
\While {<condition>}
...
\EndWhile
루프 내용 주위에 중괄호가 없습니다.
\State
전체 코드( 내부에 a를 추가했습니다 \If
); 또한 \mathit
가 \textit
. null 배열 \left[\right]
의 경우 [\,]
.
\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}