
我試圖對兩個algorithm
環境進行編號並在彼此之間留出一些空間,但我只是在旁邊得到編號?我怎樣才能在演算法之前獲得數字?
代碼:
\documentclass{article}
\usepackage{german,t1enc}
\usepackage[linesnumbered,ruled,vlined]{algorithm2e}
\usepackage{amsmath}
\renewcommand{\baselinestretch}{1.5}
\usepackage{mathtools}
\begin{document}
\begin{itemize}
\item[1.]
\begin{algorithm}[H]
\SetAlgoLined
\KwData{2 graphs T and \'{T} with nodes V and \'{V}.}
\KwResult{Find whether T and \'{T} are isomorph.}
function(T, \'{T}) \\
\Indp Find bijection of $\forall v \in V$ with $v_1, v_2 \dots , v_k$ in T so that $\pi(v)$ has the following childern $\pi(v_1), \pi(v_2), \dots, \pi(v_n)$ in \'{T}; \\
\If{the bijection is permutation}{
T and \'{T} are isomorph;
}
\end{algorithm}
\item[2.]
\begin{algorithm}[H]
\SetAlgoLined
\KwData{2 graphs T and \'{T} with nodes V and \'{V}.}
\KwResult{Find whether T and \'{T} are isomorph.}
function(T, \'{T}) \\
\Indp Find bijection of $\forall v \in V$ with $v_1, v_2 \dots , v_k$ in T so that $\pi(v)$ has the following childern $\pi(v_1), \pi(v_2), \dots, \pi(v_n)$ in \'{T}; \\
\If{the bijection is permutation}{
T and \'{T} are isomorph;
}
\end{algorithm}
\end{itemize}
\end{document}
答案1
\mbox{}
在演算法環境之前放置 a (在每個之後\item
)
環境itemize
應該替換為enumerate
提供編號而不是\item[1.]
等。
\documentclass{article}
%\usepackage{german,t1enc} % Is this needed?
\usepackage{enumitem}
\usepackage[linesnumbered,ruled,vlined]{algorithm2e}
\usepackage{amsmath}
\renewcommand{\baselinestretch}{1.5}
\usepackage{mathtools}
\begin{document}
\begin{enumerate}
\item \mbox{}
\begin{algorithm}[H]
\SetAlgoLined
\KwData{2 graphs T and \'{T} with nodes V and \'{V}.}
\KwResult{Find whether T and \'{T} are isomorph.}
function(T, \'{T}) \\
\Indp Find bijection of $\forall v \in V$ with $v_1, v_2 \dots , v_k$ in T so that $\pi(v)$ has the following childern $\pi(v_1), \pi(v_2), \dots, \pi(v_n)$ in \'{T}; \\
\If{the bijection is permutation}{
T and \'{T} are isomorph;
}
\end{algorithm}
\item \mbox{}
\begin{algorithm}[H]
\SetAlgoLined
\KwData{2 graphs T and \'{T} with nodes V and \'{V}.}
\KwResult{Find whether T and \'{T} are isomorph.}
function(T, \'{T}) \\
\Indp Find bijection of $\forall v \in V$ with $v_1, v_2 \dots , v_k$ in T so that $\pi(v)$ has the following childern $\pi(v_1), \pi(v_2), \dots, \pi(v_n)$ in \'{T}; \\
\If{the bijection is permutation}{
T and \'{T} are isomorph;
}
\end{algorithm}
\end{enumerate}
\end{document}