subalgoritmos usando algoritmos, parte a parte b

subalgoritmos usando algoritmos, parte a parte b

Actualmente estoy mostrando algoritmos en una secuencia del 1 al 9. Ahora tengo, por ejemplo, el algoritmo 7 y me gustaría llamarlo algoritmo 7a y el siguiente será el algoritmo 7b y luego el algoritmo 8 nuevamente. El siguiente es el código que uso:

\captionof{algorithm}{Consistency checker}
\begin{algorithmic}[1]
\Procedure{$\mathbf{Consistent}$}{H}
\ForEach {$n \in H$}    \Comment \emph{go through all the nodes in the graph H}
    \If {there exists a formula $\psi \in H(n)$ AND $\neg\psi \in H(n)$}
        \State \textbf{return} No;
    \EndIf  
\EndFor
\State \textbf{return} Yes;
\EndProcedure
\end{algorithmic}

También tengo lo siguiente:

\DeclareCaptionFormat{algor}{%
\hrulefill\par\offinterlineskip\vskip1pt%
\textbf{#1#2}#3\offinterlineskip\hrulefill}
\DeclareCaptionStyle{algori}{singlelinecheck=off,format=algor,labelsep=space}
\captionsetup[algorithm]{style=algori}

Lo estoy usando sin \begin{algorithm}porque de esta manera mis algoritmos siguen muy bien la página siguiente y no flotan.

¿Alguien puede sugerir una solución para tener los algoritmos 7a y 7b en la secuencia?

Respuesta1

El siguiente ejemplo mínimo define un subalgorithmsentorno con código tomado palabra por palabra deamsmath.dtx(por el subequationsmedio ambiente). Le permite al usuario rodear aquellos algorithmmensajes de correo electrónico que deben subenumerarse, entremezclados con algorithmmensajes de correo electrónico enumerados regularmente:

ingrese la descripción de la imagen aquí

\documentclass{article}

\usepackage{algpseudocode,algorithm,caption}

\DeclareCaptionFormat{algor}{%
  \hrulefill\par\offinterlineskip\vskip1pt%
  \textbf{#1#2}#3\offinterlineskip\hrulefill}
\DeclareCaptionStyle{algori}{singlelinecheck=off,format=algor,labelsep=space}
\captionsetup[algorithm]{style=algori}

\newcounter{parentalgorithm}

\makeatletter
% Code taken from amsmath (http://mirrors.ctan.org/macros/latex/required/amsmath/amsmath.dtx)
% ===========================================================================================
%    \begin{environment}{subalgorithms}
%    \begin{macrocode}
\newenvironment{subalgorithms}{%
%    \end{macrocode}
%    Before sending down the `algorithm' counter to the subordinate
%    level, add 1 using standard \cn{refstepcounter}.
%    \begin{macrocode}
  \refstepcounter{algorithm}%
%    \end{macrocode}
%    Define \cn{theparentalgorithm} equivalent to current
%    \cn{thealgorithm}. \cn{edef} is necessary to expand the current
%    value of the algorithm counter. This might in rare cases cause
%    something to blow up, in which case the user needs to add
%    \cn{protect}.
%    \begin{macrocode}
  \protected@edef\theparentalgorithm{\thealgorithm}%
  \setcounter{parentalgorithm}{\value{algorithm}}%
%    \end{macrocode}
%    And set the algorithm counter to 0, so that the normal incrementing
%    processes in the various algorithm environments will produce the
%    desired results.
%    \begin{macrocode}
  \setcounter{algorithm}{0}%
  \def\thealgorithm{\theparentalgorithm\alph{algorithm}}%
  \ignorespaces
}{%
  \setcounter{algorithm}{\value{parentalgorithm}}%
  \ignorespacesafterend
}
\makeatother

\begin{document}

\captionof{algorithm}{Consistency checker}
\begin{algorithmic}[1]
  \Procedure{$\mathbf{Consistent}$}{H}
    \For {$n \in H$}    \Comment \emph{go through all the nodes in the graph~$H$}
      \If {there exists a formula $\psi \in H(n)$ AND $\neg\psi \in H(n)$}
        \State \textbf{return} No;
      \EndIf
    \EndFor
    \State \textbf{return} Yes;
  \EndProcedure
\end{algorithmic}

\begin{subalgorithms}
\captionof{algorithm}{Consistency checker}
\begin{algorithmic}[1]
  \Procedure{$\mathbf{Consistent}$}{H}
    \For {$n \in H$}    \Comment \emph{go through all the nodes in the graph~$H$}
      \If {there exists a formula $\psi \in H(n)$ AND $\neg\psi \in H(n)$}
        \State \textbf{return} No;
      \EndIf
    \EndFor
    \State \textbf{return} Yes;
  \EndProcedure
\end{algorithmic}

\captionof{algorithm}{Consistency checker}
\begin{algorithmic}[1]
  \Procedure{$\mathbf{Consistent}$}{H}
    \For {$n \in H$}    \Comment \emph{go through all the nodes in the graph~$H$}
      \If {there exists a formula $\psi \in H(n)$ AND $\neg\psi \in H(n)$}
        \State \textbf{return} No;
      \EndIf
    \EndFor
    \State \textbf{return} Yes;
  \EndProcedure
\end{algorithmic}
\end{subalgorithms}

\captionof{algorithm}{Consistency checker}
\begin{algorithmic}[1]
  \Procedure{$\mathbf{Consistent}$}{H}
    \For {$n \in H$}    \Comment \emph{go through all the nodes in the graph~$H$}
      \If {there exists a formula $\psi \in H(n)$ AND $\neg\psi \in H(n)$}
        \State \textbf{return} No;
      \EndIf
    \EndFor
    \State \textbf{return} Yes;
  \EndProcedure
\end{algorithmic}

\end{document}

Tenga en cuenta que colocarlo \captionoffuera de un confinamiento (grupo o caja) puede causar problemas de referencia.

información relacionada