1

In the below image, I want to add two things

  1. A horizontal line after output which separate input-output from main part of algorithm
  2. I want end word (line 5) at the vertical line from if statement.

See code:

\documentclass{article}
\usepackage[linesnumbered,ruled,vlined]{algorithm2e}
\RestyleAlgo{boxruled}
\begin{document}
\begin{algorithm}[H]
\SetAlgoLined
\textbf{Input} : A graph $G$\;
\textbf{Find} : Graph and its color\\
 \uIf{Complement o}{
 Do nothng \\~\\
 }

 Do different things here

\caption{ \textsc{ Algorithm Graph  }}
\label{algo8}
\end{algorithm}

\end{document}

enter image description here

4

Here is a piece of answer:

-You explicitely ask for no end word when calling \uIf{}{}, replacing this call with \If{}{} does what you want.

-To add a horizontal line inside the algorithm you can use the solution proposed in this post. The custom macro is \hrulealg.

\documentclass{article}
\usepackage[linesnumbered,ruled,vlined]{algorithm2e}
\RestyleAlgo{boxruled}
\newcommand{\hrulealg}[0]{\vspace{1mm} \hrule \vspace{1mm}}
\begin{document}
\begin{algorithm}[H]
\SetAlgoLined
\textbf{Input} : A graph $G$\;
\textbf{Find} : Graph and its color\\
 \If{Complement o}{
 Do nothing
 }
 \hrulealg
 Do different things here

\caption{ \textsc{ Algorithm Graph  }}
\label{algo8}
\end{algorithm}

\end{document}

enter image description here

  • I have upvoted you for your work. Very good. I like it. – Sebastiano Nov 8 '18 at 12:46
  • 1
    @Sebastiano Thanks ! I am just wondering what would be a better way to center the hrule so that it is vertically centered between previous and next lines – BambOo Nov 8 '18 at 12:58

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.