9

I am trying to use the argmin and the argmax commands that I defined in an algorithm but I keep getting the argument not in the middle but on the right. Does anyone have an idea how to put the argument in the middle.

I declare the operators:

\DeclareMathOperator*{\argmin}{\arg\!\min}
\DeclareMathOperator*{\argmax}{\arg\!\max}

and I use the following packages to write algorithms:

\usepackage[chapter]{algorithm}
\usepackage{algorithmic}

Full algorithm code:

\begin{algorithm}
\begin{algorithmic} 
\STATE some statement here
\WHILE{!stop}
    \STATE $s_{i} = \argmin_{p} \| l_{j} - s_{p} \|$
\ENDWHILE
\end{algorithmic}
\end{algorithm}
  • i don't understand why you use the already-defined \arg and \min rather than just \DeclareMathOperator*{\argmin}{argmin}. – barbara beeton Nov 20 '12 at 15:10
8

$ introduces text style, you will need either \displaystyle or \limits.
(\sum, \int, \lim, … behave in the same manner: Display-style formulas have their super- and subscripts above and below the sign, in text-style formulas they are typeset like normal super- and subscripts.)

If you find both solutions unsatisfying you can define an additional command that has \limitsbuilt in:

\DeclareMathOperator*{\argmin}{argmin}
\DeclareMathOperator*{\argmax}{argmax}
\newcommand*{\argminl}{\argmin\limits}
\newcommand*{\argmaxl}{\argmax\limits}

or with your original macro names having that feature:

\DeclareMathOperator*{\argminOp}{argmin}
\DeclareMathOperator*{\argmaxOp}{argmax}
\newcommand*{\argmin}{\argminOp\limits}
\newcommand*{\argmax}{\argmaxOp\limits}

But than you could just make it without \DeclareMathOperator*:

\newcommand*{\argmin}{\operatornamewithlimits{argmin}\limits}
\newcommand*{\argmax}{\operatornamewithlimits{argmax}\limits}

I have also declared your operators with out the predefined operators \arg and \max as operators are usually in upright font anyway, and then there's no need to re-adjust the space manually (the \!).

Code A (\limits)

\documentclass{book}
\usepackage[chapter]{algorithm}
\usepackage{algorithmic}
\usepackage{amsmath}
\DeclareMathOperator*{\argmin}{argmin}
\DeclareMathOperator*{\argmax}{argmax}
\begin{document}
\begin{algorithm}
\begin{algorithmic} 
\STATE some statement here
\WHILE{!stop}
    \STATE $s_{i} = \argmin\limits_{p} \| l_{j} - s_{p} \|$
\ENDWHILE
\end{algorithmic}
\end{algorithm}
\end{document}

Code B (\displaystyle)

\documentclass{book}
\usepackage[chapter]{algorithm}
\usepackage{algorithmic}
\usepackage{amsmath}
\DeclareMathOperator*{\argmin}{argmin}
\DeclareMathOperator*{\argmax}{argmax}
\begin{document}
\begin{algorithm}
\begin{algorithmic} 
\STATE some statement here
\WHILE{!stop}
    \STATE $\displaystyle s_{i} = \argmin_{p} \| l_{j} - s_{p} \|$
\ENDWHILE
\end{algorithmic}
\end{algorithm}
\end{document}

Code C (built in \limits)

\documentclass{book}
\usepackage[chapter]{algorithm}
\usepackage{algorithmic}
\usepackage{amsmath}
\DeclareMathOperator*{\argmin}{argmin}
\DeclareMathOperator*{\argmax}{argmax}
\newcommand*{\argminl}{\argmin\limits}
\newcommand*{\argmaxl}{\argmax\limits}
\begin{document}
\begin{algorithm}
\begin{algorithmic} 
\STATE some statement here
\WHILE{!stop}
    \STATE $ s_{i} = \argminl_{p} \| l_{j} - s_{p} \|$
\ENDWHILE
\end{algorithmic}
\end{algorithm}
\end{document}

Output

enter image description here

| improve this answer | |
4

You can use \limits (but this will disrupt the regular skip between consecutive lines):

\documentclass{book}
\usepackage[chapter]{algorithm}
\usepackage{algorithmic}
\usepackage{amsmath}

\DeclareMathOperator*{\argmin}{\arg\!\min}
\DeclareMathOperator*{\argmax}{\arg\!\max}

\begin{document}

\begin{algorithm}
\begin{algorithmic} 
\STATE some statement here
\WHILE{!stop}
    \STATE $s_{i} = \argmin\limits_{p} \| l_{j} - s_{p} \|$
\ENDWHILE
\end{algorithmic}
\end{algorithm}

\end{document}

enter image description here

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.