当行断掉时调整 algorithmicx-package 中的缩进

当行断掉时调整 algorithmicx-package 中的缩进

我有这个代码

\documentclass{article}
\usepackage{algorithm}
\usepackage{algpseudocode}
\begin{document}
\begin{algorithm}
   \caption{Minimal Working Example for my Problem}
\begin{algorithmic}[1]
   \While{Indentation is a mess}
      \State Examine a very long line that looks horrible because the indentation is all messed up.
   \EndWhile
\end{algorithmic}
\end{algorithm}
\end{document}​

我希望将损坏的文本缩进到语句开始的同一列。

答案1

将长线换成top-aligned \parbox

在此处输入图片描述

\documentclass{article}
\usepackage{algorithm}% http://ctan.org/pkg/algorithms
\usepackage{algpseudocode}% http://ctan.org/pkg/algorithmicx
\begin{document}
\begin{algorithm}
  \caption{Minimal Working Example for my Problem}
  \begin{algorithmic}[1]
    \While{Indentation is a mess}
      \State \parbox[t]{\dimexpr\linewidth-\algorithmicindent}{Examine a very long line that looks horrible 
        because the indentation is all messed up.\strut}
    \EndWhile
  \end{algorithmic}
\end{algorithm}
\end{document}​

当前缩进 ( \algorithmicindent) 被移除,\linewidth以精确适应水平线宽度。\strut在末尾添加 a 可使\State没有降部的行中的行(或 s)之间实现正确的垂直对齐。

相关内容