我有一个算法,我想在它的步骤之间插入空格。
这是我的尝试:
\documentclass[12pt,a4paper,openright]{report}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{verbatim}
\usepackage{longtable}
\usepackage{graphicx}
\usepackage[square]{natbib}
\usepackage[utf8]{inputenc}
\usepackage{algorithm}% http://ctan.org/pkg/algorithms
\usepackage{algpseudocode}% http://ctan.org/pkg/algorithmicx
\algrenewcommand\algorithmicrequire{\textbf{Input:}}
\algrenewcommand\algorithmicensure{\textbf{Output:}}
\newcommand{\sfunction}[1]{\textsf{\textsc{#1}}}
\algrenewcommand\algorithmicforall{\textbf{foreach}}
\algrenewcommand\algorithmicindent{.8em}
\begin{document}
\begin{algorithm}
\caption{my algorithm}
\label{alg:ALG1}
\begin{algorithmic}[1]
\State $\text{For each line} of my algorithm I would like to insert a space between the steps but I cannot do that. The text goes out the box.$
\State $i \gets \textit{patlen}$
\If {$i > \textit{stringlen}$} \Return false
\EndIf
\State $j \gets \textit{patlen}$
\If {$\textit{string}(i) = \textit{path}(j)$}
\State $j \gets j-1$.
\State $i \gets i-1$.
\State \textbf{goto} \emph{loop}.
\State \textbf{close};
\EndIf
\State $i \gets i+\max(\textit{delta}_1(\textit{string}(i)),\textit{delta}_2(j))$.
\State \textbf{goto} \emph{top}.
\end{algorithmic}
\end{algorithm}
\end{document}
答案1
为了“启用”换行功能,您需要将文本设置为常规文本,而不是在数学模式下换行\text
:
\documentclass{article}
\usepackage{algorithm,algpseudocode}
\begin{document}
\begin{algorithm}
\caption{An algorithm}
\begin{algorithmic}[1]
\State For each line of my algorithm I would like to insert a space
between the steps but I cannot do that. The text stays inside the box.
\State Something else altogether.
\end{algorithmic}
\end{algorithm}
\end{document}