[Tex/LaTex] Issue with algorithm2e “input” alignment

algorithm2eindentation

If you look at the image below you will see that on the 4th line of the input, the alignment resets for some reason and I'm not sure why. Could someone show me how to fix this?

enter image description here

    \begin{algorithm}[H]
        \SetKwInOut{Input}{input}
        \SetKwInOut{Output}{output}

        \Input{A set of men $M$ such that for all $m \in M$, $m$ is free and has a preference list containing each woman $w \in W$ \\
        A set of women $W$ such that for all $w \in W$, $w$ is free and has a preference list containing each man $m \in M$}
        \Output{A perfect matching between $M$ and $W$ with no strong instability}
    \end{algorithm}

Best Answer

Your problem is that you're using \\ inside the defined \Input. If you use \newline, instead, it works fine.

MWE:

\documentclass{article}
\usepackage[titlenumbered,ruled]{algorithm2e}
\begin{document}
\begin{algorithm}[H]
    \SetKwInOut{Input}{input}
    \SetKwInOut{Output}{output}

    \Input{A set of men $M$ such that for all $m \in M$, $m$ is free and has a preference list containing each woman $w \in W$ \newline 
    A set of women $W$ such that for all $w \in W$, $w$ is free and has a preference list containing each man $m \in M$}
    \Output{A perfect matching between $M$ and $W$ with no strong instability}
    \caption{Modified Gale-Shapley algorithm allowing indifferences}
\end{algorithm}
\end{document} 

Output:

enter image description here

Related Question