1
\documentclass{article}

\usepackage[utf8]{inputenc}

\usepackage{latexsym}

\usepackage[linesnumbered,ruled,vlined]{algorithm2e}

\SetCommentSty{mycommfont}
\usepackage[linkbordercolor={0 0 1}]{hyperref}
\usepackage{nameref}
\renewcommand{\labelitemi}{$\bullet$}
\usepackage{enumerate}
\usepackage{caption}
%\captionsetup[figure]{labelfont=bf}
\captionsetup{labelsep=none}
\usepackage{subcaption}
\usepackage[compatibility=false]{caption}

\RestyleAlgo{boxruled}
\LinesNumbered

\usepackage{amsmath,amssymb,fancyhdr,url}
\usepackage{graphicx}

\usepackage{mathrsfs}
\usepackage{tabularx,environ,amsmath,amssymb}
   \begin{document}
    \begin{algorithm}[H]
    \SetAlgoLined
    \textbf{Input} : An a $p^t$, prime $p$, 
     integer $t$ and data s above\;
    \textbf{Find} : A swq $G$\;
    \vspace{0.3cm}
    \textbf{begin}\;

    \hspace{0.5cm} $L =\phi;B=\phi$\;
    \hspace{0.5cm} repeat\;
    \hspace{1cm} select largest ord$_G(a)$\;
    \hspace{1cm} $B=B\cup \{a\}$\;
    \hspace{1cm} $L^{'} $\;
   \hspace{1cm} \textbf{for} (each $b \in L^{'}$) remove all elements in 
   $U(b)$ from $M$\;
  \hspace{1cm} $L=L\cup L^{'}$\;
  \hspace{0.5cm} until $(\sum_{a_j \in B}R(a_j) =t)$\;
  \textbf{end}



     \caption{Algorithm}
     \end{algorithm}

\end{document}

Question : How to design a vertical line between begin and end statement of the algorithm?

See the output:

enter image description here

  • For the future: Please format pasted code with the respective markdown. This increases readability ba a LOT :) – Raven Mar 21 '19 at 17:14
  • For Ravens comment: Hint if using a browser, you can highlight the code and hit Ctrl-k to get it formatted this way. – daleif Mar 21 '19 at 17:24
  • @daleif I do Ctrl-k but it works only for the first line of the code. – nice guy Mar 21 '19 at 17:45
  • @regarding the formatting of code in questions: Select the block of code first and then press Ctrl+k or the {} button. Regarding your question: You might want to use \Begin, \End , \Input,... instead of \textbf{...} – leandriis Mar 21 '19 at 18:32
2

You need to use the keywords defined by algorithm2e. Here's a better markup that does just that:

enter image description here

\documentclass{article}

\usepackage[linesnumbered,ruled,vlined]{algorithm2e}

\SetKwInOut{KwInput}{Input}
\SetKwInOut{KwFind}{Find}

\begin{document}

\begin{algorithm}
  \SetAlgoLined
  \KwInput{An a $p^t$, prime $p$, integer $t$ and data s above}
  \KwFind{A swq $G$}
  \BlankLine
  \Begin{
    $L = \phi$; $B = \phi$\;
    \Repeat{$\sum_{a_j \in B} R(a_j) = t$}{
      select largest $\mathrm{ord}_G(a)$\;
      $B = B \cup \{a\}$\;
      $L'$\;
      \For{each $b \in L'$}{
        remove all elements in $U(b)$ from $M$\;
      }
      $L = L \cup L'$\;
    }
  }
  \caption{Algorithm caption}
\end{algorithm}

\end{document}
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.