隐藏 algorithmc 中某些行的编号

隐藏 algorithmc 中某些行的编号

我有以下 LaTeX 算法的代码。我只需要隐藏前三行的编号;有什么建议吗?

\documentclass{article}

\usepackage{algorithm}
\usepackage{algorithmic}
\usepackage{amsfonts,mathrsfs}

 \algsetup{
    linenodelimiter={}
}

\begin{document}

\begin{algorithm}
    \caption{: IMR Algorithm}\label{imr}
    \footnotesize{
        \begin{algorithmic}[1]
            \STATE \textbf{Input:}  $\left(\mathscr{U},\mathscr{A,V}\right)$ //IIS
            \STATE \  \  \  \  \  \  \  \  \  \  \  \ $m$ 
            \STATE \textbf{Output:} $\underline{\Psi}_{\mathfrak{U}_{\zeta_{j}}}$ 
            \FOR {$i =1 $ \textbf{to} $m$}
            \STATE $R_{u_i} := \left\{u_i\right\}$
            \FOR {$j =1 $ \textbf{to} $m$}
            \IF{$\left(u_j,u_i\right) \in S$ as per Defintion 2}
            \STATE $R_{u_i} := R_{u_i} \bigcup \left\{u_j\right\}$ //as per Eq. \ref{relation-r}
            \ENDIF
            \ENDFOR
            \ENDFOR

            \FOR {$i =1 $ \textbf{to} $m$}
            \STATE $R^{-1}_{u_i} := \left\{u_i\right\}$
            \FOR {$j =1 $ \textbf{to} $m$}
            \IF{$\left(u_i,u_j\right) \in S$ as per Defintion 2}
            \STATE $R^{-1}_{u_i} := R^{-1}_{u_i} \bigcup \left\{u_j\right\}$ 
            \ENDIF
            \ENDFOR
            \ENDFOR
            \FOR {\textbf{each} $R^{-1}_{u_i} $}
            \STATE Calculate the class $\psi^{-1}_{u_{i}}$ as per Definition 4
            \ENDFOR
            \STATE Calculate the lower approximation $\underline{\Psi}_{\mathfrak{U}_{\zeta_{j}}}$ 
            \STATE Calculate the upper approximation $\overline{\Psi }_{\mathfrak{U}    _{\zeta_{j}}}$
    \end{algorithmic}}
\end{algorithm}

\end{document}

答案1

创建您自己的\STATEnonum,只设置一个\item不带数字的(因为algorithmic无论如何只是一个列表):

在此处输入图片描述

\documentclass{article}

\usepackage{algorithm,algorithmic}
\usepackage{amsfonts,mathrsfs}
\usepackage{caption,mathtools}

\captionsetup[algorithm]{
  labelsep = colon
}
\algsetup{
  linenodelimiter={}
}

\newcommand{\STATEnonum}{\item[]}
\newcommand{\definedas}{\vcentcolon=}

\begin{document}

\begin{algorithm}
  \caption{IMR Algorithm}
  \begin{algorithmic}[1]
    \STATEnonum \begin{tabular}{@{} l @{\ } l @{}}
      \textbf{Input:}  & $(\mathscr{U}, \mathscr{A, V})$ {\itshape // IIS} \\
                       & $m$                                               \\
      \textbf{Output:} & $\underline{\Psi}_{\mathfrak{U}_{\zeta_j}}$
    \end{tabular}
    \FOR{$i = 1 $ \textbf{to} $m$}
      \STATE $R_{u_i} \definedas \{u_i\}$
      \FOR{$j = 1 $ \textbf{to} $m$}
        \IF{$(u_j, u_i) \in S$ as per Definition~2}
          \STATE $R_{u_i} \definedas R_{u_i} \cup \{u_j\}$ {\itshape // as per Eq.~X}
        \ENDIF
      \ENDFOR
    \ENDFOR

    \FOR{$i = 1 $ \textbf{to} $m$}
      \STATE $R^{-1}_{u_i} \definedas \{u_i\}$
      \FOR{$j = 1 $ \textbf{to} $m$}
        \IF{$(u_i, u_j) \in S$ as per Definition~2}
          \STATE $R^{-1}_{u_i} \definedas R^{-1}_{u_i} \cup \{u_j\}$ 
        \ENDIF
      \ENDFOR
    \ENDFOR
    \FOR{\textbf{each} $R^{-1}_{u_i} $}
      \STATE Calculate the class $\psi^{-1}_{u_i}$ as per Definition~4
    \ENDFOR
    \STATE Calculate the lower approximation $\underline{\Psi}_{\mathfrak{U}_{\zeta_j}}$ 
    \STATE Calculate the upper approximation $\overline{\Psi}_{\mathfrak{U}_{\zeta_j}}$
  \end{algorithmic}
\end{algorithm}

\end{document}

我还修复了以下问题:

  • 水平对齐多个输入输出使用tabular;

  • 定义\definedas\vcentcolon=而不是:=明确地用来显示定义。

  • 用过的caption自动格式化标题中的冒号。

答案2

最简单的方法是将这 3 行从 \begin{algorithmic} 中移出,但仍在 \begin{algorithm} 范围内。您将获得:

\begin{algorithm}
    \caption{: IMR Algorithm}\label{imr}
            \textbf{Input:}  $\left(\mathscr{U},\mathscr{A,V}\right)$ //IIS\\
 \hspace*{3.7em} $m$ \\
\textbf{Output:} $\underline{\Psi}_{\mathfrak{U}_{\zeta_{j}}}$ 
    \footnotesize{
        \begin{algorithmic}[1]
            \FOR {$i =1 $ \textbf{to} $m$}
            \STATE $R_{u_i} := \left\{u_i\right\}$
            \FOR {$j =1 $ \textbf{to} $m$}
            \IF{$\left(u_j,u_i\right) \in S$ as per Defintion 2}
            \STATE $R_{u_i} := R_{u_i} \bigcup \left\{u_j\right\}$ //as per Eq. \ref{relation-r}
            \ENDIF
            \ENDFOR
            \ENDFOR

            \FOR {$i =1 $ \textbf{to} $m$}
            \STATE $R^{-1}_{u_i} := \left\{u_i\right\}$
            \FOR {$j =1 $ \textbf{to} $m$}
            \IF{$\left(u_i,u_j\right) \in S$ as per Defintion 2}
            \STATE $R^{-1}_{u_i} := R^{-1}_{u_i} \bigcup \left\{u_j\right\}$ 
            \ENDIF
            \ENDFOR
            \ENDFOR
            \FOR {\textbf{each} $R^{-1}_{u_i} $}
            \STATE Calculate the class $\psi^{-1}_{u_{i}}$ as per Definition 4
            \ENDFOR
            \STATE Calculate the lower approximation $\underline{\Psi}_{\mathfrak{U}_{\zeta_{j}}}$ 
            \STATE Calculate the upper approximation $\overline{\Psi }_{\mathfrak{U}    _{\zeta_{j}}}$
    \end{algorithmic}
}
\end{algorithm}

相关内容