使用 itemize 或其他環境對演算法進行編號

使用 itemize 或其他環境對演算法進行編號

我試圖對兩個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}

在此輸入影像描述

相關內容