我有這個代碼
\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)之間進行正確的垂直對齊。