4

How can I reduce this large space between colon and text in line with Input: ? Also please how to remove align of text after Input: and Precondition: ? I am using algorithm2e. Is it possible with this package? Here is my code:

\documentclass{article}

\usepackage[linesnumbered,ruled]{algorithm2e}
\usepackage{amsmath}
\usepackage{setspace}

\begin{document}

    \begin{algorithm}
        \SetAlgorithmName{Algorithm}{}{}
        \SetKwInOut{Precondition}{Precondition~}
        \SetKwInOut{Input}{Input~}
        \Input{~There is some fancy input definition.}
        \Precondition {~There is some fancy precondition.}
        \begin{doublespace}
            \eIf{$b=0$}
            {
                return $a$
            }
            {
                $b$
            }
        \end{doublespace}   
        \caption{Best algorithm ever.}
    \end{algorithm}

\end{document}

This is actual state:

enter image description here

This is wanted final state:

enter image description here

  • Your example, apart from not being complete, also does not compile – Moriambar Apr 28 '17 at 22:04
  • @Moriambar Sorry for that, should be ok now. – delusionX Apr 28 '17 at 22:12
4

You could use SetKwInput for the first conditions, as SetKwInOut works just adjusting the space as you have seen.

Here an example

\documentclass{article}

\usepackage[linesnumbered,ruled]{algorithm2e}
\usepackage{amsmath}
\usepackage{setspace}

\begin{document}

    \begin{algorithm}
        \SetAlgorithmName{Algorithm}{}{}
              \SetKwInput{Precondition}{Precondition~}
                              \SetKwInput{Input}{Input~}


        \Input{~There is some fancy input definition.}
        \Precondition {~There is some fancy precondition.}
        \begin{doublespace}
            \eIf{$b=0$}
            {
                return $a$
            }
            {
                $b$
            }
        \end{doublespace}   
        \caption{Best algorithm ever.}
    \end{algorithm}

\end{document}

result:

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.