是否有这样的包,其中 for 循环或 if 语句的结尾是不是显示?我不介意 LaTeX 代码本身,但我介意结果。
例如,我正在使用这个:
\documentclass{article}
\usepackage{algorithm}
\usepackage{algorithmic}
\newcommand{\algorithmicinput}{\textbf{input}}
\newcommand{\INPUT}{\item[\algorithmicinput]}
\begin{document}
\begin{algorithm}[H]
\caption{Dolphinn: Preprocessing (data structure)}
\label{DolphinnPrep}
\begin{algorithmic}
\INPUT{Parameter $d'$.}
\STATE Initialize empty hashtable $T$.
\FOR{$i = 1$ to $d'$}
\STATE Sample $h_i \in F$ u.a.r.
\FOR{each $x \in h_i(P)$}
\STATE{Flip a fair coin and assign the result to $f_i(x)$.}
\ENDFOR
\ENDFOR
\STATE{For all $p \in P$, $f(p)=(f_1(h_1(p)), \ldots, f_{d'}(h_{d'}(p)))$.}
\STATE{For all $p \in P$, add $p$ to the bucket of $T$ with key f(p)$.}
\end{algorithmic}
\end{algorithm}
\end{document}
结果是:
注意“end for”行。我想删除它们。怎么做?
对于 if 语句也需要同样的行为。
答案1
而不是使用algorithmic
, 使用algcompatible
使用noend
包选项:
\documentclass{article}
\newcommand{\MM}{\mathcal{M}}
\usepackage{algorithm}
\usepackage[noend]{algcompatible}
\newcommand{\algorithmicinput}{\textbf{input}}
\newcommand{\INPUT}{\item[\algorithmicinput]}
\begin{document}
\begin{algorithm}[H]
\caption{Dolphinn: Preprocessing (data structure)}
\label{DolphinnPrep}
\begin{algorithmic}
\INPUT{Metric $(\MM, d_{\MM})$, approximation factor $c>1$, LSH family $F=F(c,r)$, data set $P \subset \MM$, parameter $d'$.}
\STATE Initialize empty hashtable $T$.
\FOR{$i = 1$ to $d'$}
\STATE Sample $h_i \in F$ u.a.r.
\FOR{each $x \in h_i(P)$}
\STATE{Flip a fair coin and assign the result to $f_i(x)$.}
\ENDFOR
\ENDFOR
\STATE{For all $p \in P$, $f(p)=(f_1(h_1(p)), \ldots, f_{d'}(h_{d'}(p)))$.}
\STATE{For all $p \in P$, add $p$ to the bucket of $T$ with key $f(p)$.}
\end{algorithmic}
\end{algorithm}
\end{document}