13

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}

1 Answer 1

19

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

1
  • 1
    Hello, do you know if there's a way to remove the space between "input" and ":"?
    – MariyaKav
    Commented Feb 13, 2023 at 13:51

You must log in to answer this question.

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