In LaTeX, there is no direct built-in command for writing argmax and argmin, which is why many people initially find it a bit tricky. But once you understand the techniques, it actually becomes very easy to write them.
Now I will show you, step by step and in depth, how to write these operators in different ways, using appropriate packages and formatting them nicely.
Using \operatorname
In LaTeX, the \operatorname command is very useful for defining mathematical operators, as it makes them appear in a professional style similar to \sum or \lim.
\documentclass{article}
\usepackage{amsmath,amssymb}
\begin{document}
\[
\operatorname*{arg\,max}_{x \in \mathbb{R}} f(x), \quad
\operatorname*{argmin}_{y \in \mathbb{R}} g(y) % Without space
\]
\end{document}
One important difference is that if you use \operatorname*, the subscript will appear below the operator (just like in summation).
If you use only \operatorname, the subscript stays on the right. So for larger display equations, using \operatorname* is the best option.
Creating Shortcut Commands
Since these operators are used very frequently, you can define your own shortcut using \DeclareMathOperator.
\documentclass{article}
\usepackage{amsmath,amssymb}
\DeclareMathOperator*{\argmax}{arg\,max}
\DeclareMathOperator*{\argmin}{arg\,min}
\begin{document}
\[
x^* = \argmax_{x \in \mathbb{R}} f(x), \quad
y^* = \argmin_{y \in \mathbb{R}} g(y)
\]
\end{document}
Once defined, you can directly use \argmax or \argmin without having to type \operatorname again and again. This is especially useful in research papers, theses, or long notes.
The mathtools Package
The mathtools package is an extension of amsmath. It allows more customization for subscripts and superscripts.
\documentclass{article}
\usepackage{amsmath,mathtools,amssymb}
\DeclareMathOperator*{\argmax}{arg\,max}
\DeclareMathOperator*{\argmin}{arg\,min} % Without Space
\begin{document}
\[
\argmax\limits_{x \in [0,1]} f(x), \quad
\argmin\limits_{n \to \infty} g(n)
\]
\end{document}
Here, by using \limits or \nolimits, you can choose whether the subscript appears below or on the side.
Writing with \underset
The \underset command is used to place something directly underneath a symbol
For example, if you want to write \min with a variable below it, this works perfectly. In the same way, you can use it for \arg\min or \arg\max.
\documentclass{article}
\usepackage{amsmath,amsfonts}
\begin{document}
\[ \underset{x \in \mathbb{R}}{\arg\min} \; f(x) \]
\[ \underset{y \in Y}{\arg\max} \; g(y) \]
\end{document}
Notice that whatever you put inside \underset will appear directly below the symbol.
So if you write \underset{x}{\arg\min}, the variable x will neatly appear under the operator.
Note: In the above examples, the \mathbb command has been used (for sets like ℝ).
For this reason, each code snippet includes amsfonts or amssymb as an additional package to support the \mathbb command.