[Tex/LaTex] Algorithm: write if-then-return or else-return in one line

algorithm2ealgorithms

I can easily generate the following algorithm statements using algorithm2e package. As can be seen from the image, return statement (should hold for other statements too) will be placed in a new line even it is very short. How can I write if-then-return or else-return in one line?

enter image description here

P.S. the code to generate the above is as follows:

... ...
\uIf{$\max_{\mathcal{AV}} > \theta_5$}
{
    \Return the tracklet with $\max_{\mathcal{AV}}$.
}
\Else
{
    \Return no speaker.
}   
... ...

Best Answer

You can use \lIf instead of \uIf and \lElse instead of \Else.

MWE

\documentclass{report}
\usepackage{algorithm2e}

\begin{document}

\begin{algorithm}
\lIf{$\max_{\mathcal{AV}} > \theta_5$}
{
    \Return the tracklet with $\max_{\mathcal{AV}}$.
}
\lElse
{
    \Return no speaker.
}  
\end{algorithm}

\end{document} 

Output

enter image description here


EDIT

If you don't want to print the semicolon at the end of each line, simply issue the command

\DontPrintSemicolon

MWE

\documentclass{report}
\usepackage{algorithm2e}

\begin{document}

\begin{algorithm}
\DontPrintSemicolon
\lIf{$\max_{\mathcal{AV}} > \theta_5$}
{
    \Return the tracklet with $\max_{\mathcal{AV}}$.
}
\lElse
{
    \Return no speaker.
}
\end{algorithm}

\end{document} 

Output

enter image description here