禁用特定行的行号

禁用特定行的行号

有没有办法关闭特定行的行号algorithm2e?我需要在关键字后加粗:。所以我尝试重新定义这些宏:

\renewcommand{\KwIn}[1]{\textbf{Input:} #1}
\renewcommand{\KwOut}[1]{\textbf{Output:} #1}

但尝试之后:

\begin{algorithm}[h]  

\SetAlgoNoLine
\DontPrintSemicolon
\LinesNumbered

\KwIn{$(X_{t-1}, u_t, z_t)$}\\
\KwOut{$X_t$}
...
...
...
\end{algorithm}

算法

因此我需要关闭前 2 行(关键字行)的行号。或者指定新关键字,:关键字名称后将以粗体显示。这\SetKwInput{Input}{Input}只会在名称:后生成正常内容Input输入: (X...))。我在文档中搜索如何调整输入/输出关键字的样式,但没有:找到有关结尾的内容。有人可以帮忙吗?

答案1

以下是重新定义的一种可能性\SetKwInOut

\documentclass{article}
\usepackage[linesnumbered]{algorithm2e}

\makeatletter
\renewcommand{\SetKwInOut}[2]{%
  \sbox\algocf@inoutbox{\KwSty{#2}\algocf@typo:}%
  \expandafter\ifx\csname InOutSizeDefined\endcsname\relax% if first time used
    \newcommand\InOutSizeDefined{}%
    \sbox\algocf@inoutbox{\KwSty{#2}\algocf@typo\textbf{:}~}\setlength{\inoutindent}{\wd\algocf@inoutbox}%
  \else% else keep the larger dimension
    \ifdim\wd\algocf@inoutbox>\inoutsize%
    \sbox\algocf@inoutbox{\KwSty{#2}\algocf@typo\textbf{:}~}\setlength{\inoutindent}{\wd\algocf@inoutbox}%
    \fi%
  \fi% the dimension of the box is now defined.
  \algocf@newcommand{#1}[1]{%
    \ifthenelse{\boolean{algocf@inoutnumbered}}{\relax}{\everypar={\relax}}%
%     {\let\\\algocf@newinout\hangindent=\wd\algocf@inoutbox\hangafter=1\parbox[t]{\inoutsize}{\KwSty{#2}\algocf@typo\hfill:}~##1\par}%
    {\let\\\algocf@newinout\hangindent=\inoutindent\hangafter=1\KwSty{#2}\algocf@typo\textbf{:}~##1\par}%
    \algocf@linesnumbered% reset the numbering of the lines
  }}%
\makeatother
\begin{document}

\begin{algorithm}
\SetKwInOut{Input}{Input}
\SetKwInOut{Output}{Output}
\Input{A bitmap $Im$ of size $w\times l$}
\Output{A partition of the bitmap}
\BlankLine
\emph{special treatment of the first line}\;
\For{$i\leftarrow 2$ \KwTo $l$}{
\emph{special treatment of the first element of line $i$}\;
}
\caption{disjoint decomposition}\label{algo_disjdecomp}
\end{algorithm}\DecMargin{1em}


\end{document}

在此处输入图片描述

相关内容