我用\DeclareMathOperator*{\argmin}{argmin}
它来获取 argmin 参数。一切都很好,但如果我在算法表中输入它,它无法显示正确的输出。下图显示了这种情况
这张图片的代码是
\documentclass{article}
\usepackage{algorithm,algpseudocode,float}
\usepackage{amsmath}
\DeclareMathOperator*{\argmin}{argmin}
%-----------
\makeatletter
\newenvironment{breakablealgorithm}
{% \begin{breakablealgorithm}
\begin{center}
\refstepcounter{algorithm}% New algorithm
\hrule height.8pt depth0pt \kern2pt% \@fs@pre for \@fs@ruled
\renewcommand{\caption}[2][\relax]{% Make a new \caption
{\raggedright\textbf{\ALG@name~\thealgorithm} ##2\par}%
\ifx\relax##1\relax % #1 is \relax
\addcontentsline{loa}{algorithm}{\protect\numberline{\thealgorithm}##2}%
\else % #1 is not \relax
\addcontentsline{loa}{algorithm}{\protect\numberline{\thealgorithm}##1}%
\fi
\kern2pt\hrule\kern2pt
}
}{% \end{breakablealgorithm}
\kern2pt\hrule\relax% \@fs@post for \@fs@ruled
\end{center}
}
\makeatother
\begin{document}
$$
a = \argmin_s
$$
\begin{breakablealgorithm}
\caption{XXXXXXXXX}
\begin{algorithmic}[1]
\State{$\text{A} = \argmin_s B$}
\end{algorithmic}
\end{breakablealgorithm}
\end{document}
我现在的问题是为什么它在算法内部不能正常工作。
答案1
在algorithmic
环境中,进入数学模式时,您处于常规文本样式中。文本样式中的运算符的限值以这种方式显示,而不是显示在下方/上方。您必须强制显式\displaystyle
以相同方式设置它:
\documentclass{article}
\usepackage{algorithm,algpseudocode,amsmath}
\DeclareMathOperator*{\argmin}{argmin}
\begin{document}
\[
a = \argmin_s
\]
\begin{algorithm}
\caption{XXXXXXXXX}
\begin{algorithmic}[1]
\State $\text{A} = \displaystyle\argmin_s B$
\end{algorithmic}
\end{algorithm}
\end{document}
但我不会这么做。