0

I am trying to write if-else loop in an algorithm within the substeps. Somehow it doesn't appear as expected.

\documentclass[]{article}

\usepackage{algorithm,algpseudocode,float}
\usepackage{graphicx}
\usepackage{amsmath,paralist}
\usepackage{color,listings}
\input{listings-modelica.cfg}
\lstset{language = Modelica,
       basicstyle=\fontsize{9pt}{10.5pt}\selectfont,
       backgroundcolor = \color{white},
       aboveskip = 0pt, 
       belowskip = 0pt}

\makeatletter
\newenvironment{breakablealgorithm}
  {% \begin{breakablealgorithm}
   \begin{center}
     \refstepcounter{algorithm}% New algorithm
     \hrule height.8pt depth0pt \kern2pt% \@fs@pre for \@fs@ruled
     \renewcommand{\caption}[2][\relax]{% Make a new \caption
       {\raggedright\textbf{\ALG@name~\thealgorithm} ##2\par}%
       \ifx\relax##1\relax % #1 is \relax
         \addcontentsline{loa}{algorithm}{\protect\numberline{\thealgorithm}##2}%
       \else % #1 is not \relax
         \addcontentsline{loa}{algorithm}{\protect\numberline{\thealgorithm}##1}%
       \fi
       \kern2pt\hrule\kern2pt
     }
  }{% \end{breakablealgorithm}
     \kern2pt\hrule\relax% \@fs@post for \@fs@ruled
   \end{center}
  }
\makeatother

\newcounter{algsubstate}
\renewcommand{\thealgsubstate}{\alph{algsubstate}}
\newenvironment{algsubstates}
  {\setcounter{algsubstate}{0}%
   \renewcommand{\State}{%
     \stepcounter{algsubstate}%
     \Statex {\footnotesize\thealgsubstate:}\space}}
  {}

\newcommand{\algoref}[1]{Algorithm~\ref{#1}}
\newcommand{\comment}{\newline \Comment}

\begin{document}
\begin{algorithm}
\caption{Equations in a material stream}
\begin{algorithmic}[1]

\State Overall Material Balance
\begin{equation}
F = L + V
\end{equation}

\State Component wise Material Balance
\begin{equation}
z_i F = x_i L + y_i V
\end{equation}

\State Equilibrium equation:
\begin{equation}
y_i = K_i x_i
\end{equation}

\State Vapor Phase Mole Fraction:
\begin{equation}
\beta = \frac{V}{F}
\end{equation}

\State Summation equaton:
\begin{equation}
\sum_{i=1}^n y_i = 1
\end{equation}

\begin{equation}
\sum_{i=1}^n x_i = 1
\end{equation}

\State Phase mole fraction
\begin{algsubstates}
    \State 
        \If{$P \geq P_{bubble}$}
            \begin{equation}
            x_i = z_i
            \end{equation}
            \begin{equation}
            y_i = 0
            \end{equation}
    \State
        \ElsIf {$P \geq P_{bubble}$}
            \begin{equation}
            x_i = \frac{L_i}{F_i}
            \end{equation}
            \begin{equation}
            y_i = \frac{V_i}{F_i}
            \end{equation}
    \State
        \Else
            \begin{equation}
            y_i = z_i
            \end{equation}    
            \begin{equation}
            x_i = 0
            \end{equation}
        \EndIf
\end{algsubstates}
\end{algorithmic}
\end{algorithm}

\end{document}

In theenter image description here image, what appears at step 7 should appear at point a, what appears at step 8 should appear at point b and what appears at step 9 should appear at point c.

Your Answer

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

Browse other questions tagged or ask your own question.