在 Latex 中,如何将多行块包含在一个枚举项中?

在 Latex 中,如何将多行块包含在一个枚举项中?

在 Latex 中:

\documentclass{article}
\usepackage{algorithm}
\usepackage{algpseudocode}
\usepackage[utf8]{inputenc}
\title{example}
\author{ }
\date{October 2022}
\begin{document}
\maketitle
\section{Introduction}

\begin{algorithm}
    \begin{algorithmic}
    
            \State $InvariantList \gets FD(PDDL)$
            \State $StateVar \gets StateVar(LatPlan)$
            
            \While{$InvariantList \neq $ $\emptyset$}
                \State 
                    \begin{enumerate}
                        \item \textit{Inv} = $highInv($InvariantList) 
                        \item Train LatPlan by enforcing \textit{Inv}
                        \item  $StateVarTmp \gets StateVar(LatPlan)$ \\ \If{$StateVarTmp <    $ StateVar} \State Keep Inv in the loss function and in InvariantList\Else \State Discard Inv from the loss function and from InvariantList \EndIf
                        \item other item
                    \end{enumerate}
                    
            \EndWhile
    \end{algorithmic}
\end{algorithm}

\end{document}

这并没有实现我所期望的结果:

在此处输入图片描述

即,我想删除“如果”块的数字,因为我希望该块成为第 3 项的一部分。

任何想法 ?

答案1

使用 enumitem 包和一些 DIY

  • \setlist{nosep}

     \documentclass{article}
     \usepackage{algorithm}
     \usepackage{algpseudocode}
     \usepackage{enumitem}
    
     \begin{document}
     \setlist{nosep}
     \begin{algorithm}
     \begin{algorithmic}
         \State $InvariantList \gets FD(PDDL)$
         \State $StateVar \gets StateVar(LatPlan)$
         \While{$InvariantList \neq $ $\emptyset$}
             \State              
                 \begin{enumerate}\vspace{-1\baselineskip}
                     \item \textit{Inv} = $highInv($InvariantList) 
                     \item Train LatPlan by enforcing \textit{Inv}
                     \item  
                     $StateVarTmp \gets StateVar(LatPlan)$
                 \end{enumerate}
                 \begin{itemize}[label =]\vspace{-1.\baselineskip}
                     \item\If{$StateVarTmp <    $ StateVar} \State Keep Inv in the loss function and in InvariantList\Else \State Discard Inv from the loss function and from InvariantList \EndIf
                 \end{itemize}
                     \begin{enumerate}[resume]
                 \item other item
                 \end{enumerate} 
         \EndWhile         
     \end{algorithmic}
     \end{algorithm}
     \end{document}
    

在此处输入图片描述

相关内容