[Tex/LaTex] Sub-numbering in an algorithm

algorithmicxalgorithmsline-numbering

How can I add sub steps to a numbered step in an algorithm as shown in the image:

enter image description here

\documentclass{article}

\usepackage{algorithm,algpseudocode}

\begin{document}

\begin{algorithm}
  \caption{Square Root Cubature Kalman Filter SRCKF}

  \textbf{Time update}

  \begin{algorithmic}[1]
    \State Factorize the state error covariance matrix 
      \begin{equation}
        P_{k-1|k-1} = S_{k-1|k-1}S_{k-1|k-1}^T
      \end{equation}  
    \State Evaluate the cubature points (i=1,2,...,$m = 2n_x$)
      \begin{equation}
        X_{i,k-1|k-1} = \hat{x}_{k-1|k-1} + S_{i,k-1|k-1}\zeta_i
      \end{equation}
    \State Evaluate the propagated cubature points through the process equation (i=1,2,...,$m = 2n_x$)
      \begin{equation}
      X_{i,k|k-1}^*=f(X_{i,k-1|k-1},u_{k-1})
      \end{equation} 
    \State Estimate the predicted state


    \State Estimate the predicted error covariance
      \begin{equation}
      P_{k|k-1}=\frac{1}{m}\sum_{i=1}^m{X_{i,k|k-1}^*X_{i,k|k-1}^{*T}}-\hat{x}_{k|k-1}\hat{x}_{k|k-1}^T+Q_{k-1} 
      \end{equation} 
  \end{algorithmic}
\end{algorithm}

\end{document}

Best Answer

You can use a list-like environment algsubstates like I defined below. The enumeration formatting matches that of the regular \State (using \footnotesize):

enter image description here

\documentclass{article}

\usepackage{algorithm,algpseudocode}

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

\begin{document}

\begin{algorithm}
  \caption{Square Root Cubature Kalman Filter SRCKF}

  \textbf{Time update}

  \begin{algorithmic}[1]
    \State Factorize the state error covariance matrix 
      \begin{equation}
        P_{k-1 \mid k-1} = S_{k-1 \mid k-1} S_{k-1 \mid k-1}^T
      \end{equation}  
    \State Evaluate the cubature points ($i = 1,2,\ldots,m = 2n_x$)
      \begin{equation}
        X_{i,k-1 \mid k-1} = \hat{x}_{k-1 \mid k-1} + S_{i,k-1 \mid k-1} \zeta_i
      \end{equation}
    \State Evaluate the propagated cubature points through the process equation ($i = 1,2,\ldots,m = 2n_x$)
      \begin{equation}
        X_{i,k \mid k-1}^* = f(X_{i,k-1 \mid k-1},u_{k-1})
      \end{equation} 
    \State Estimate the predicted state
      \begin{algsubstates}
        \State First
        \State Second
        \State Third
        \State Last
      \end{algsubstates}
    \State Estimate the predicted error covariance
      \begin{equation}
      P_{k \mid k-1} = \frac{1}{m}\sum_{i=1}^m X_{i,k \mid k-1}^* X_{i,k \mid k-1}^{*T}
        - \hat{x}_{k \mid k-1}\hat{x}_{k \mid k-1}^T + Q_{k-1} 
      \end{equation} 
  \end{algorithmic}
\end{algorithm}

\end{document}

The above code doesn't allow for referencing within the algsubstates. However, the following should:

\newcounter{algsubstate}
\makeatletter
\renewcommand{\thealgsubstate}{\arabic{ALG@line}.\alph{algsubstate}}
\makeatother
\newenvironment{algsubstates}
  {\setcounter{algsubstate}{0}%
   \renewcommand{\State}{%
     \refstepcounter{algsubstate}%
     \Statex {\footnotesize\alph{algsubstate}:}\space}}
  {}

\references will be of the form <state>.<substate> (but could be changed).