# Algorithmic: Put If and EndIf into same line

I use the algorithmic package to create a pseudo-code-source in latex. I have a source with many short if-statements. The fact that the END (from EndIf) is put in a new line every time leads to a lengthy layout:

\documentclass[11pt,a4paper,leqno,fleqn]{article}
\usepackage{algpseudocode}
\usepackage[Algorithmus]{algorithm}
\begin{document}
\begin{algorithm}
\caption{WHILE-Modulo}
\begin{algorithmic}[1]
\Require f($x_1,x_2$)
\State $x_z := 1$
\While{$x_z \not = 0$}
\If{$x_z = 1$} \If{$x_1 = 0$} $x_z = 10$ \EndIf \EndIf
\If{$x_z = 2$} $x_3 := x_1 \dot{-}x_2$\EndIf
\If{$x_z = 3$} $x_4 := x_2 \dot{-}x_1$\EndIf
\If{$x_z = 4$} \If{$x_3 = 0$} $x_z = 7$\EndIf \EndIf
\If{$x_z = 5$} $x_1 := x_3$\EndIf
\If{$x_z = 6$} $x_z = 2$\EndIf
\If{$x_z = 7$} \If{$x_4 = 0$} $x_z = 9$\EndIf \EndIf
\If{$x_z = 8$} $x_z = 10$\EndIf
\If{$x_z = 9$} $x_1 := x_1 \dot{-} x_2$\EndIf
\If{$x_z = 10$} $x_z = 0$\EndIf
\If{$x_z = 11$} $x_z = 0$\EndIf
\EndWhile
\end{algorithmic}
\end{algorithm}
\end{document}


However, I want single If-Statements to be in one line, similar to this:

Do you have ideas? I am grateful for all input

• Welcome to TeX.SX! Please make your code compilable (if possible), or at least complete it with \documentclass{...}, the required \usepackage's, \begin{document}, and \end{document}. That may seem tedious to you, but think of the extra work it represents for TeX.SX users willing to give you a hand. Help them help you: remove that one hurdle between you and a solution to your problem. – jub0bs Jun 10 '14 at 12:53
• Sorry for the unconvenience, the source is now compileable – thunfischtoast Jun 10 '14 at 12:56

You can create your own "Intermediate IF" (or one-liner IF) statement using the following:

\documentclass{article}
\usepackage{algpseudocode}
\usepackage[Algorithmus]{algorithm}
\algnewcommand{\IIf}[1]{\State\algorithmicif\ #1\ \algorithmicthen}
\algnewcommand{\EndIIf}{\unskip\ \algorithmicend\ \algorithmicif}
\begin{document}
\begin{algorithm}
\caption{WHILE-Modulo}
\begin{algorithmic}[1]
\Require f($x_1,x_2$)
\State $x_z := 1$
\While{$x_z \not = 0$}
\If{$x_z = 1$} \IIf{$x_1 = 0$} $x_z = 10$ \EndIIf \EndIf
\IIf{$x_z = 2$} $x_3 := x_1 \dot{-}x_2$\EndIIf
\IIf{$x_z = 3$} $x_4 := x_2 \dot{-}x_1$\EndIIf
\If{$x_z = 4$} \IIf{$x_3 = 0$} $x_z = 7$\EndIIf \EndIf
\IIf{$x_z = 5$} $x_1 := x_3$\EndIIf
\IIf{$x_z = 6$} $x_z = 2$\EndIIf
\If{$x_z = 7$} \IIf{$x_4 = 0$} $x_z = 9$\EndIIf \EndIf
\IIf{$x_z = 8$} $x_z = 10$\EndIIf
\IIf{$x_z = 9$} $x_1 := x_1 \dot{-} x_2$\EndIIf
\IIf{$x_z = 10$} $x_z = 0$\EndIIf
\IIf{$x_z = 11$} $x_z = 0$\EndIIf
\EndWhile
\end{algorithmic}
\end{algorithm}
\end{document}