我有这个代码
\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
将长线换成t
op-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)之间实现正确的垂直对齐。