How can I write 'begin' and 'end' statement at the top and bottom the following code like this?A sample pseuodcode with begin and end statement
Besides using algorithm and algopseudocode package I can write Require and Ensure statement. Those are not properly aligned. Is there any way to align like the attached pic?
% book example for classicthesis.sty
\documentclass[
% Replace twoside with oneside if you are printing your thesis on a single side
% of the paper, or for viewing on screen.
%oneside,
twoside,
11pt, a4paper,
footinclude=true,
headinclude=true,
cleardoublepage=empty
]{scrbook}
\usepackage{lipsum}
\usepackage[linedheaders,parts,pdfspacing]{classicthesis}
\usepackage{amsmath}
\usepackage{amsthm}
\usepackage{acronym}
\usepackage{algpseudocode}
\usepackage{algorithm}
\begin{document}
\chapter{A Chapter}
\begin{algorithm}
\caption{Apriori algorithm}
\begin{algorithmic}[1]
\State $L_{1} \leftarrow Frequent 1-itemset $
\State $k \leftarrow 2$
\While{$L_{k-1} \neq \phi$}
\State $Temp \leftarrow candidateItemSet (L_{k-1})$
\State $C_{k} \leftarrow frequencyOfItemSet (Temp)$
\State $L_{k} \leftarrow compareItemSetWithMinimumSupport (C_{k}, minsup) $
\State $k \leftarrow k + 1$
\EndWhile\\
\Return L
\end{algorithmic}
\end{algorithm}
\end{document}
Best Answer
Just define (in
algpseudocode
style)and then use
\Begin
and\End
as in the following example:Output
Just a remark. You should not write
but
as in my example.
If you want a different indentation for
\Return
you can do the following.Add
in the preamble and use
\BState
instead of\State
in front of\Return
.MWE
Output