## 编译环境
操作系统
* Windows 10
Tex发行版
* TexLive `2020`
## 我的问题
我使用了 `algorithm` 系列包渲染一段伪代码,导包如下所示:
``...
## 编译环境
操作系统
* Windows 10
Tex发行版
* TexLive `2020`
## 我的问题
我使用了 `algorithm` 系列包渲染一段伪代码,导包如下所示:
```
\usepackage{algorithm}
\usepackage{algorithmicx}
\usepackage{algpseudocode}
\floatname{algorithm}{Algorithm}
\renewcommand{\algorithmicrequire}{\textbf{Require:}}
\renewcommand{\algorithmicensure}{\textbf{Require:}}
```
我想要实现这么一个效果:

但是我写的代码在编译过之后, `for` 语句内部第二行在换行后会顶在首部而不是缩进来,如下所示:

我的代码如下:
```Latex
\begin{algorithm}[t]
\caption{Model-Agnostic Meta-Learning}
\begin{algorithmic}[1]
\Require $p(\mathcal{T})$ : distribution over tasks
\Ensure $\alpha, \beta$ : step size hyperparameters
\State randomly initialize $\theta$
\While {not done}
\State Sample batch of tasks $\mathcal{T}_{i} \sim p(\mathcal{T})$
\ForAll {$\mathcal{T}_{i}$}
\State Evaluate $\nabla_{\theta} \mathcal{L}_{\mathcal{T}_{i}}\left(f_{\theta}\right)$
with respect to $K$ examples
\State Compute adapted parameters with
gradient descent: $\theta_{i}^{\prime}=\theta-\alpha \nabla_{\theta} \mathcal{L}_{\mathcal{T}_{i}}\left(f_{\theta}\right)$
\EndFor
\State Updat $\theta \leftarrow \theta-\beta \nabla_{\theta} \sum_{\mathcal{T}_{i} \sim p(\mathcal{T})} \mathcal{L}_{\mathcal{T}_{i}}\left(f_{\theta_{i}^{\prime}}\right)$
\EndWhile
\end{algorithmic}
\end{algorithm}
```
回答: 2020-12-15 18:56
一周热门 更多>