![如何将算法直接放在段落后面](https://linux22.com/image/452183/%E5%A6%82%E4%BD%95%E5%B0%86%E7%AE%97%E6%B3%95%E7%9B%B4%E6%8E%A5%E6%94%BE%E5%9C%A8%E6%AE%B5%E8%90%BD%E5%90%8E%E9%9D%A2.png)
我想在一小段之后立即开始我的算法,而不是从下一页开始。我尝试了很多方法,例如将浮动更改为“h!”或“H”,但都无济于事。有人能帮帮我吗?
梅威瑟:
\documentclass[10pt,a4paper, openright,titlepage,fleqn,%
headinclude,footinclude,BCOR5mm,%
numbers=noenddot,cleardoublepage=empty]{scrreprt}
\usepackage{algorithm}
\usepackage{algpseudocode}
\begin{document}
The following is some random algorithm.
\begin{algorithm}[H]
\caption{: (optimization procedure}
\label{alg:cmaes}
\begin{algorithmic}[1]
\Procedure{(1+1)-CMA-ES } {n, m, z, i}
\State Check the initial or existing iteration parameters.
\If{$i = 0$} \Comment{If it is the start of iteration, use initial parameters.}
\State $\boldsymbol{x} = \boldsymbol{x}_0$ \Comment{Parental var., shape = (n, 1)}
\State $\boldsymbol{\sigma} = \boldsymbol{\sigma}_0$ \Comment{e.g.: 0.5}
\State $\boldsymbol{A} = I$ \Comment{(n, n)}
\EndIf
\EndProcedure
\end{algorithmic}
\end{algorithm}
\end{document}
为了给您提供一些图像,以下是结果(使用真实脚本,不同于 MWE):
由于某种原因,算法从新的(下一页)页面开始。我可以做些什么让算法紧跟在段落之后(从与段落相同的页面开始)吗?