3

I am trying to put a line in algorithm2e:

\documentclass{IEEEtran}
\usepackage[ruled,linesnumbered]{algorithm2e}
\begin{document}
\IncMargin{1.5em}
\begin{algorithm}  
    algorithm here\;
    \hrule
    algorithm here\;
    \caption{Caption}
\end{algorithm}
\DecMargin{1.5em}
\end{document}

output

There is a gap at the start and end of the line (indicated by the red arrows). I tried the code from here but it also contains gap. I also tried \moveleft with \vbox which although removes the gap but I have to hardcode the measurements, and it doesn't work with different \IncMargin values in different algorithms.

How to remove this gap? The gap is also affected by \IncMargin, I don't want it to be affected by \IncMargin.

1 Answer 1

4

The left margin is \algomargin.

\documentclass{IEEEtran}
\usepackage[ruled,linesnumbered]{algorithm2e}

\newcommand{\algosep}{%
  \par
  \nointerlineskip
  \moveleft\algomargin\vbox{\hrule width \columnwidth}
  \nointerlineskip
}

\begin{document}

\IncMargin{1.5em}
\begin{algorithm}
  algorithm here\;
  \algosep
  algorithm here\;
\caption{Caption}
\end{algorithm}
\DecMargin{1.5em}

\end{document}

output

The same code but without \IncMargin and \DecMargin will produce

no incmargin

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.