算法包中有多行时的缩进

算法包中有多行时的缩进

我正在使用算法包,并得到了以下代码:

\documentclass{article}
\usepackage{algorithm}
\usepackage{algpseudocode}
\begin{document}
\begin{algorithmic}[1]
\Function {BalanceCascade}{}
\State $i \leftarrow 0, f \leftarrow \sqrt[T-1]{\frac{\left | P \right |}{\left | N \right |}}$, some very very very very very very very very very very very very very very very very long goes here, so this will create a few new lines
\EndFunction 
\end{algorithmic}
\end{document}

我得到了以下结果: 在此处输入图片描述 有没有办法将新行缩进到第一行的开头之下?

更新:如果我按照@Bobyandbob 提出的解决方案,线条会变得太近: 在此处输入图片描述 中间没有空格线结束函数

答案1

首先,我展示您所拥有的内容,然后在 中展示它\parbox,尝试使用一些水平list长度来获得正确的宽度(它很接近,但不完全正确)。最后,我再次使用\parbox,但手动指定宽度以匹配右边距。

为了获得正确的垂直位置和间距,我必须使用选项[t]\parbox以 结尾\strut

\documentclass{article}
\usepackage{algorithm}
\usepackage{algpseudocode}
\begin{document}
\begin{algorithmic}[1]
\Function {BalanceCascade}{}
\State $i \leftarrow 0, f \leftarrow \sqrt[T-1]{\frac{\left | P \right |}{%
  \left | N \right |}}$, some very very very very very very very very very
  very very very very very very very long goes here, so this will create a 
  few new lines
\EndFunction 

\Function {BalanceCascade}{}
\State \parbox[t]{\dimexpr\textwidth-\leftmargin-\labelsep-\labelwidth}{%
  $i \leftarrow 0, f \leftarrow \sqrt[T-1]{\frac{\left | P \right |}{%
  \left | N \right |}}$, some very very very very very very very very very
  very very very very very very very long goes here, so this will create a 
  few new lines\strut}
\EndFunction 

\Function {BalanceCascade}{}
\State \parbox[t]{313pt}{%
  $i \leftarrow 0, f \leftarrow \sqrt[T-1]{\frac{\left | P \right |}{%
  \left | N \right |}}$, some very very very very very very very very very
  very very very very very very very long goes here, so this will create a 
  few new lines\strut}
\EndFunction 
\end{algorithmic}

\noindent Here is the left margin
\end{document}

在此处输入图片描述

相关内容