如何在我的偽演算法中插入 end for 並使其更加空間友好?

如何在我的偽演算法中插入 end for 並使其更加空間友好?

這是我的偽算法:

\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}

我的問題是

  1. 當我運行它時,我沒有結束。
  2. 我想減少它所佔用的空間,但是當我放在\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

相關內容