2

Set up

I am trying to combine my own \leftbar code with some algorithm code. The confusing part about this table us the use of \eIf function. However i would like to replicate it manually but with different words and a different look.

MWE

\documentclass{book}

%for original algorithm 
\usepackage{amsmath}
\usepackage[linesnumbered,ruled]{algorithm2e}

%for leftbar code


     \usepackage{framed} 
     \usepackage{xcolor}%if highlight needed

    \renewenvironment{leftbar}[1][\hsize] 
    {%
        \def\FrameCommand
        {%
            {\color{black}\vrule width 0.65pt} %
            \hspace{2pt} %
            %\fboxsep=\FrameSep\colorbox{yellow}%highlight 
        }%
        \MakeFramed{\hsize#1\advance\hsize-\width\FrameRestore}%
    }
    {\endMakeFramed}% start \leftbar and \endleftbar 




\begin{document}

%Original table to try and replicate

\begin{algorithm}
    \SetKwInOut{Input}{Input}
    \SetKwInOut{Output}{Output}

    \underline{Initialise alogrithm} $(a,b)$\;
    \Input{input}
    \Output{output}
    \eIf{if condiion $math code$}
      {
        return step 1 $result$\;
      }
      {
        return step 2 $result$\;
      }
    \caption{Name of algorithm}
\end{algorithm}



%my way of doing it with leftbar 

\begin{algorithm}
    \SetKwInOut{Input}{Input}
    \SetKwInOut{Output}{Output}

    \underline{Initialise alogrithm} $(a,b)$\;
    \Input{input}
    \Output{output}
    \underline{Example of computation} \textbf{input} given \textbf{output:}
      \leftbar
        return step 1 $result$\;
        step 2 \;
        step 3 \;
      \endleftbar
      \textbf{next iteration}
      \leftbar
        return step 2 $result$\;
        step 4 \;
        step 5 \;
        \vdots
      \endleftbar
     \textbf{terminate}
    \caption{Name of algorithm}
\end{algorithm}




\end{document} 

Goal

As you can see the format in the modified algorithm table is slightly off. I'm aiming to get the bar to be after the numbers but before the text or before the numbers altogether. How do i fix this? I'm assuming i have to make another \leftbar command and since i already use \leftbar for something else, is there a way to rename this function as \leftbarAlg?

1

The package your using has some inbuilt functions for this purpose. Take a look at: https://en.wikibooks.org/wiki/LaTeX/Algorithms

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.