我正在使用算法包,并得到了以下代码:
\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}
答案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}