算法环境放置错误,不在我想要的位置(直接在子节语句下)。我知道关于这个问题的流行答案,比如像图形那样使用float
包和参数,但我试过了,它再次失败了,在前面,但在代码中它应该在后面[H]
Algorithm 2
subsection 2.2
附言:我float
现在有包含的包裹
序言:
\documentclass[12pt,letterpaper,oneside,reqno]{amsart}
\usepackage{amsfonts}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{amsthm}
\usepackage{float}
\usepackage{mathrsfs}
\usepackage{colonequals}
\usepackage[font=small,labelfont=bf]{caption}
\usepackage[left=1in,right=1in,bottom=1in,top=1in]{geometry}
\usepackage[pdfpagelabels,hyperindex,colorlinks=true,linkcolor=blue,urlcolor=magenta,citecolor=green]{hyperref}
\usepackage{setspace}
\usepackage{csquotes}
\usepackage{graphicx}
\usepackage{algorithm}
\usepackage{algpseudocode}
\onehalfspacing
\emergencystretch=1em
\newtheorem{thm}{Theorem}[section]
\newtheorem{cor}[thm]{Corollary}
\newtheorem{lem}[thm]{Lemma}
\newtheorem{examp}[thm]{Example}
\newtheorem{definition}[thm]{Definition}
\numberwithin{equation}{section}
乳胶代码:
\subsection{Building solution space tree}
Generation of abstract solution space tree is quit simple using Breadth-first approach as following pseudocode shows
\input{pseudocodes/build_solution_tree_pseudocode.tex}
\subsection{Finding terminal nodes of solution space tree}
\input{pseudocodes/create_set_of_terminal_nodes_pseudocode.tex}
\subsection{Finding solution candidates}
\subsection{Finding globally optimal solution}
\begin{algorithm}[H]
\caption{Build solution space tree.}
\begin{algorithmic}[1]
\State \textbf{Inputs:} Set of variables $X$, initial constraint value $c\in\mathbb{Z}^n$.
\State \textbf{Outputs:} Set of nodes $L$.
\State Create queue $Q$
\State Create list $L$
\State $InitialVariableSet \leftarrow \{x_i \; | \; x_i \in X \; \wedge \; x_i \leq c\}$
\For {each variable $x$ in $InitialVariableSet$}
\State $constraint \leftarrow c - x$
\State $node \leftarrow Node(x, constraint, NULL)$
\State $Q \leftarrow node$
\State $L \leftarrow node$
\EndFor
\While{queue $Q$ in not empty}
\State $currentNode \leftarrow \mathrm{dequeue \; from \; Q}$
\State $currentConstraint \leftarrow \mathrm{constraint \; value \; of \; the \; currentNode}$
\State $set \leftarrow \{x_i \; | \; x_i \in X \; \wedge \; x_i \leq currentConstraint\}$
\For {each variable $s$ in $set$}
\State $constraint \leftarrow currentConstraint - x$
\State $node \leftarrow Node(x, constraint, currentNode)$
\State $currentNode.ChildNodes \leftarrow node$
\State $Q \leftarrow node$
\EndFor
\EndWhile
\end{algorithmic}
\end{algorithm}
\begin{algorithm}[H]
\caption{Generate set of Terminal nodes.}
\begin{algorithmic}[1]
\State \textbf{Inputs:} Set of nodes $L$.
\State \textbf{Outputs:} Set of terminal nodes $T$.
\State Create queue $Q$
\State Create list $T$
\For {each node $x$ in $L$}
\State $Q \leftarrow x$
\While{queue $Q$ in not empty}
\State $currentNode \leftarrow \mathrm{dequeue \; from \; Q}$
\If {$currentNode \; \mathrm{is \; terminal \; node}$}
\State $T \leftarrow currentNode$
\State $continue$
\EndIf
\For {each node $s$ in $currentNode$ child nodes}
\State $Q \leftarrow s$
\EndFor
\EndWhile
\EndFor
\end{algorithmic}
\end{algorithm}
输出图像:
答案1
添加 \usepackage{placeins}
到您的序言中并更改您的第二个算法如下:
\begin{algorithm}[ht!] % do not use H <<<<
\caption{Generate set of Terminal nodes.}
\begin{algorithmic}[1]
\State \textbf{Inputs:} Set of nodes $L$.
\State \textbf{Outputs:} Set of terminal nodes $T$.
\State Create queue $Q$
\State Create list $T$
\For {each node $x$ in $L$}
\State $Q \leftarrow x$
\While{queue $Q$ in not empty}
\State $currentNode \leftarrow \mathrm{dequeue \; from \; Q}$
\If {$currentNode \; \mathrm{is \; terminal \; node}$}
\State $T \leftarrow currentNode$
\State $continue$
\EndIf
\For {each node $s$ in $currentNode$ child nodes}
\State $Q \leftarrow s$
\EndFor
\EndWhile
\EndFor
\end{algorithmic}
\end{algorithm}
\FloatBarrier% add to the end<<<<<<<<<<<
amsart
问题在于定义的方式subsection
。参见在 AMS 文档类中用 \subsection 交换材料
正如您在第一小节中看到的,现在\subsection
创建了一个运行标题。
选项 2重新定义子节。添加到你的序言中
\makeatletter
\renewcommand\subsection{\@startsection{subsection}{2}{\z@}%
{.5\linespacing\@plus.7\linespacing}
{0.5ex \@plus .2ex}%
{\normalfont\bfseries}}
\makeatother
你会得到
下一页