
현재 1-9 순서로 알고리즘을 표시하고 있습니다. 이제 예를 들어 알고리즘 7이 있고 이름을 알고리즘 7a로 지정하고 다음 알고리즘은 알고리즘 7b가 되고 다시 알고리즘 8이 됩니다. 다음은 내가 사용하는 코드입니다.
\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}
또한 나는 다음을 가지고 있습니다 :
\DeclareCaptionFormat{algor}{%
\hrulefill\par\offinterlineskip\vskip1pt%
\textbf{#1#2}#3\offinterlineskip\hrulefill}
\DeclareCaptionStyle{algori}{singlelinecheck=off,format=algor,labelsep=space}
\captionsetup[algorithm]{style=algori}
나는 이것을 없이 사용하고 있는데, \begin{algorithm}
이렇게 하면 내 알고리즘이 다음 페이지로 잘 따라가고 떠다니지 않기 때문입니다.
누군가 알고리즘 7a와 7b를 순서대로 포함하는 솔루션을 제안할 수 있습니까?
답변1
다음 최소 예는 subalgorithms
다음에서 그대로 가져온 코드로 환경을 정의합니다.amsmath.dtx
( subequations
환경을 위해). 이를 통해 사용자는 algorithm
하위 열거되어야 하는 s를 정기적으로 열거되는 algorithm
s와 혼합하여 둘러쌀 수 있습니다.
\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}
\captionof
격리(그룹 또는 상자) 외부에 배치하면 참조 문제가 발생할 수 있습니다.