extra horizontal space after the pseudocode

I have an extra horizontal white space at the end of my pseudocode that I cannot get rid of with negative \hspace. Here is my minimal code:

\documentclass[journal,transmag]{IEEEtran}
\usepackage[ruled,linesnumbered]{algorithm2e}
\usepackage{amsmath}
\usepackage{amssymb}

\begin{document}
something.
%
\SetKwInput{KwInputs}{Inputs}
\SetKwInput{KwOutput}{Output}
\SetKwInput{kwInit}{Init}
\SetAlCapSkip{1em}
\SetNlSty{textbf}{}{}
\SetNlSkip{0.8em}
\IncMargin{1em}
\begin{algorithm}[t]
\DontPrintSemicolon
\Indm
\KwInputs{inputs}
\KwOutput{outputs}
\Indp
$\theta_k=\tau_{k}$\;
\end{algorithm}
something else.

\end{document}


How can I get rid of the space before "something else"?

Thank you.

2 Answers

Every end of line after the % up to \begin{algorithm} contributes a space.

\documentclass[journal,transmag]{IEEEtran}
\usepackage[ruled,linesnumbered]{algorithm2e}
\usepackage{amsmath}
\usepackage{amssymb}

\begin{document}
something.
%
\SetKwInput{KwInputs}{Inputs}%
\SetKwInput{KwOutput}{Output}%
\SetKwInput{kwInit}{Init}%
\SetAlCapSkip{1em}%
\SetNlSty{textbf}{}{}%
\SetNlSkip{0.8em}%
\IncMargin{1em}%
\begin{algorithm}[t]
\DontPrintSemicolon
\Indm
\KwInputs{inputs}
\KwOutput{outputs}
\Indp
$\theta_k=\tau_{k}$\;
\end{algorithm}
something else.

something. something else. % for checking
\end{document}


However, I usually advise of placing such floating objects between paragraphs, that is, with a blank line before and one below. So, in your case,

something. Something else.

\SetKwInput{KwInputs}{Inputs}
\SetKwInput{KwOutput}{Output}
\SetKwInput{kwInit}{Init}
\SetAlCapSkip{1em}
\SetNlSty{textbf}{}{}
\SetNlSkip{0.8em}
\IncMargin{1em}
\begin{algorithm}[t]
[...]
\end{algorithm}

Another paragraph starts here.


The spaces generated by the end-of-lines will do nothing in this case.

• another catch by the spurious-space catcher. you might want to mention that these spaces are not compressed into one by tex because they aren't contiguous. – barbara beeton May 3 '16 at 14:05

For IEEEtran class, USE "\par" to separate the content into two different paragraphs. The screenshot is attached for your reference. Hope this helps.