例如,我想进一步缩进一个if-then-else
块,就像在这个中完成的那样问题。
\documentclass{article}
\usepackage{algpseudocode}
\usepackage{algorithm}
\begin{document}
\begin{algorithm}
\caption{my alg}
\begin{algorithmic}[1]
\If{condition} % <-- would like to indent this whole block further
\State{$x=1$}
\EndIf
\end{algorithmic}
\end{algorithm}
\end{document}
答案1
您可以定义一个“空”块来创建新的嵌套级别。
新的块应该没有文本,并且不会产生多余的线条。
\documentclass{article}
\usepackage{algpseudocode}
\usepackage{algorithm}
\algblockdefx{Nest}{EndNest}{}{}
\algtext*{Nest}{}
\algtext*{EndNest}{}
\begin{document}
\begin{algorithm}
\caption{my alg}
\begin{algorithmic}[1]
\If{condition} % <-- would like to indent this whole block further
\State{$x=1$}
\EndIf
\Statex
\Nest
\If{condition} % <-- would like to indent this whole block further
\State{$x=1$}
\EndIf
\EndNest
\Statex
\Nest
\Nest
\If{condition} % <-- would like to indent this whole block further
\State{$x=1$}
\EndIf
\EndNest
\EndNest
\end{algorithmic}
\end{algorithm}
\end{document}