我在 algorithm2e 中使用\DontPrintSemicolon
,但注释行末尾的分号仍然存在。这个问题本应在版本 5.0 中得到解决,但我使用的是版本 5.2,仍然有这个问题。这是 MWE;非常感谢任何线索:
\documentclass[12pt]{article}
\usepackage[lined,boxed]{algorithm2e}% using version 5.2
\usepackage{amsmath}
\begin{document}
\begin{algorithm}[ht]
\DontPrintSemicolon
\SetKwInOut{Declare}{Declare}
\caption{COM\_MIN Algorithm}\label{alg:commin}
\KwIn{ \texttt{R}: relation; $Pr$: set of simple predicates}
\KwOut{$Pr'$: set of simple predicates}
\Declare{$F$: set of minterm fragments}
\Begin{
$Pr' \leftarrow \emptyset$; $F \leftarrow \emptyset$; \hfill \{initialize\} \\
find $p_{i} \in Pr$ such that $p_{i}$ partitions \texttt{R} according to $Rule~1$ \;
$Pr' \leftarrow Pr' \cup p_{i}$ \;
$Pr \leftarrow Pr - p_{i}$ \;
$F \leftarrow F \cup f_{i}$ ; \hfill \{$f_{i}$ is the minterm fragment according to
$p_{i}$\} \\
}
\end{algorithm}
\end{document}
答案1
\DontPrintSemicolon
仅影响打印在 表示的行尾的分号\;
。但是您明确地将分号放在注释之前,因此它们不会被删除。只需删除;
即可获得所需的结果:
\begin{algorithm}[ht]
\DontPrintSemicolon
\SetKwInOut{Declare}{Declare}
\caption{COM\_MIN Algorithm}\label{alg:commin}
\KwIn{ \texttt{R}: relation; $Pr$: set of simple predicates}
\KwOut{$Pr'$: set of simple predicates}
\Declare{$F$: set of minterm fragments}
\Begin{
$Pr' \leftarrow \emptyset$; $F \leftarrow \emptyset$ \hfill \{initialize\} \\
find $p_{i} \in Pr$ such that $p_{i}$ partitions \texttt{R} according to $Rule~1$ \;
$Pr' \leftarrow Pr' \cup p_{i}$ \;
$Pr \leftarrow Pr - p_{i}$ \;
$F \leftarrow F \cup f_{i}$ \hfill \{$f_{i}$ is the minterm fragment according to
$p_{i}$\} \\
}
\end{algorithm}