算法环境内的缩进

算法环境内的缩进

考虑以下代码片段:

\documentclass{article}
\usepackage[textwidth=8.5cm]{geometry}

\usepackage{amsmath}

\usepackage{algorithm}
\usepackage{algpseudocode}
\usepackage{parskip}
\pagenumbering{gobble}



\begin{document}
    \hrule
    \smallskip
    \begin{algorithmic}[1]
        \State Initialize $Q$ to hold all pairs $(w_i,w_j)$ s.t. $v_i$ and $v_j$ are T-C
        \While {Sequence size is bigger than 1}
        \State Find T-C pair $(w_i,w_j)$ s.t. $w_i+w_j$ is minimal
        \State Combine $v_i$ and $v_j$ to a new node $v_k$, and form new sequence (if $v_i$ and $v_j$ are non-adjacent, let $v_k$ take the left position in the resultant sequence)
        \State Update $Q$ accordingly
        \EndWhile
    \end{algorithmic}
    \smallskip
    \hrule
\end{document}

其结果如下:

在此处输入图片描述

我怎样才能缩进步骤4。与 While 循环中的其他行对齐?
我尝试用//或 添加来打破它们\hspace{},但这不起作用……

答案1

尝试\State \parbox[t]{\dimexpr\linewidth-\algorithmicindent}{long sentences}

相关内容