
這是我的偽算法:
\begin{algorithm}[t]
\caption{Generate Disseminated Sequences}\label{euclid}
\begin{algorithmic}[1]
\Function{output}{$memory,input$}
\State $\text{initialize}~ B \gets \text{all zeros}$
\For{$i = 1$ to ${sizeIn}$\text{+1}}
\State $\text{return}~OUTPUT\gets \text{convert \textit{B} to decimal }$
\For{$j = memorySize$ to $2$}
\State $M[j+1] \gets M[j]$
\EndFor
\State $B[i] \gets inputString[i]$
\EndFor
\EndFunction
\end{algorithmic}
\end{algorithm}
我的問題是
- 當我運行它時,我沒有結束。
- 我想減少它所佔用的空間,但是當我放在
\vspace
後面\end{algorithmic}
或\end{algorithm}
最後一行時,就會從這些演算法空間中出來。
答案1
你可能正在使用
\usepackage[noend]{algpseudocode}
這會從結構中刪除所有結尾子句。看algpseudocode
沒有結束區塊文本。刪除noend
恢復結束子句的選項。
環境algorithmic
被定義為一個清單。之後的空間可以使用調整etoolbox
修補:
\documentclass{article}
\usepackage{algpseudocode,etoolbox}
\begin{document}
Something above \verb|algorithmic|.
\begin{algorithmic}[1]
\State First state
\State Second state
\State Third state
\State Last state
\end{algorithmic}
Something below \verb|algorithmic|.
\hrulefill
\AfterEndEnvironment{algorithmic}{\vspace{50pt}}
Something above \verb|algorithmic|.
\begin{algorithmic}[1]
\State First state
\State Second state
\State Third state
\State Last state
\end{algorithmic}
Something below \verb|algorithmic|.
\end{document}
然而,更典型的是人們使用algorithmic
中的環境algorithm
,這是一個浮動塊。在這方面,請參閱刪除圖形後面和文字之前的空格變更與浮動周圍間距相關的任何參數。
具體來說,您可能有興趣調整長度\textfloatsep
或\intextsep
。