1

I have the following example

\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}

however I do not want if and else be in two separate lines, but only in one.

Could anyone help me, please? Thanks in advance

2 Answers 2

1

Define \lIfElse{<condition>}{<true>}{<false>} to insert the <false> clause as part of <true>:

enter image description here

\documentclass{article}

\usepackage{algorithm2e}

\newcommand{\lIfElse}[3]{\lIf{#1}{#2 \textbf{else}~#3}}

\begin{document}
    
\begin{algorithm}
  \lIfElse{$a$}{True}{False}
  \lIfElse{$b$}{\Return True}{\Return False}
\end{algorithm}
    
\end{document}
3

The easiest is probably to do it manually:

\documentclass{report}
\usepackage{algorithm2e}
\usepackage[left=1cm]{geometry}
\begin{document}
    
    \begin{algorithm}
        \lIf{$\max_{\mathcal{AV}} > \theta_5$}
        {
            \Return the tracklet with $\max_{\mathcal{AV}}$. ; \textbf{else return} no speaker.
        }
    \end{algorithm}
    
\end{document}

Result:

enter image description here

Note that I made the page a bit wider (with left margin reduced to 1cm) otherwise the text didn't fit on one line.

If you want to emulate the slightly larger space between else and return then you can do something like \textbf{else\enspace return}.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .