我有以下算法代码:
\documentclass{article}
\usepackage{graphicx}
\usepackage{algorithm}
\usepackage{algpseudocode}
\usepackage{amsmath}
\begin{document}
\begin{algorithm}
\caption{Pseudo-cod}
\begin{algorithmic}
\Statex \textbf{Step 1:} Solve Model.
\Statex \textbf{Step 2:} Let $t\leftarrow 0$
\For{$i \in \mathcal{I}$}
\State Let $t \leftarrow t+1$
\If{$\theta_{i} <- r^{tot}$}
\State $r^{tot}\times 0.9$
\EndIf
\EndFor
\Statex \textbf{Step 3:}
\If{$\theta_{i} \geq r^{tot}$}
\State stop and go to \textbf{Step 4}
\EndIf
\Statex \textbf{Step 4:} Solve the updated Model as IP.
\end{algorithmic}
\end{algorithm}
\end{document}
但是,我现在想删除该If
条件,只保留do
该行。我已经尝试过了,但没有得到想要的结果。
\documentclass{article}
\usepackage{graphicx}
\usepackage{algorithm}
\usepackage{algpseudocode}
\usepackage{amsmath}
\begin{document}
\begin{algorithm}
\caption{Pseudo-cod}
\begin{algorithmic}
\Statex \textbf{Step 1:} Solve Model.
\Statex \textbf{Step 2:} Let $t\leftarrow 0$
\Statex \textbf{do}
\qquad \State Let $t \leftarrow t+1$
\Statex \qquad \If{$\theta_{i} <- r^{tot}$}
\Statex \qquad \qquad $r^{tot}\times 0.9$
\Statex \qquad \EndIf
\Statex \textbf{Step 3:}
\If{$\theta_{i} \geq r^{tot}$}
\State stop and go to \textbf{Step 4}
\EndIf
\Statex \textbf{Step 4:} Solve the updated Model as IP.
\end{algorithmic}
\end{algorithm}
\end{document}
答案1
快速破解:定义一个新块并将格式更改为你喜欢的格式
\documentclass{article}
\usepackage{graphicx}
\usepackage{algorithm}
\usepackage{algpseudocode}
\usepackage{amsmath}
\algblockdefx[NAME]{Do}{EndDo}{\textbf{Do}}{\vspace*{-\baselineskip}}
\begin{document}
\begin{algorithm}
\caption{Pseudo-cod}
\begin{algorithmic}
\Statex \textbf{Step 1:} Solve Model.
\Statex \textbf{Step 2:} Let $t\leftarrow 0$
\Do
\State Let $t \leftarrow t+1$
\If{$\theta_{i} <- r^{tot}$}
\State $r^{tot}\times 0.9$
\EndIf
\EndDo
\Statex \textbf{Step 3:}
\If{$\theta_{i} \geq r^{tot}$}
\State stop and go to \textbf{Step 4}
\EndIf
\Statex \textbf{Step 4:} Solve the updated Model as IP.
\end{algorithmic}
\end{algorithm}
\end{document}