How can I create arrows with a text below the arrows like in this picture? I tried it with LaTeX, but it didn't work like that in this picture.
-
1Welcome to TeX.SE! Could you please add a little example of what you tried?– CarLaTeXNov 14, 2022 at 18:08
-
@CarLaTeX 0=x^2 {{-4x}_{\displaystyle\uparrow_{p}}}+{{3}_{\displaystyle\uparrow_{q}}}– CeloNov 14, 2022 at 18:35
-
6Consider editing your question and including this snippet of code. Better yet, proivde a minimal working example (MWE).– Jasper HabichtNov 14, 2022 at 18:36
5 Answers
\documentclass{article}
\usepackage{amsmath}
\begin{document}
\[
0 = x^{2}
- \underset{\displaystyle p}{\underset{\uparrow}{4}}x
+ \underset{\displaystyle q}{\underset{\uparrow}{3}}
\]
\end{document}
This is a nice use case for stackengine
:
\documentclass[border=10pt]{standalone}
\usepackage{stackengine}
\begin{document}
$ 0=x^2 -{} \stackMath\Shortunderstack{{4} {\uparrow} {p}}x + \stackMath\Shortunderstack{{3} {\uparrow} {q}} $
\end{document}
One of the many possible ways to add arrows in the desired manor is
\documentclass{article}
\usepackage{amsmath}
\begin{document}
\begin{align*}
0 = x^2 - &4 \, x + 3 \\
& \uparrow \hspace{6mm} \uparrow \\
& p \hspace{6mm} q
\end{align*}
\end{document}
A small variation of @Jasper Habicht answer:
- for arrows are used
arrows.meta
library oftikz
package \stackMath
is moved to begin of equation
\documentclass[margin=3mm, varwidth]{standalone}
\usepackage{tikz}
\usetikzlibrary{arrows.meta}
\newcommand\tikzuparrow{\tikz\draw[-{Straight Barb[scale=0.8]}] (0,0) -- ++ (0,0.5);}
\usepackage{amsmath}
\usepackage{stackengine}
\begin{document}
\[\stackMath
0 = x^2 - \Shortunderstack{4 {\tikzuparrow} p} x
+ \Shortunderstack{3 {\tikzuparrow} q}
\]
\end{document}
An important aspect is that the arrow and the descriptor should not add horizontal space (but it's up to you to avoid clashes in other situations).
\documentclass{article}
\usepackage{amsmath}
\newcommand{\subdesc}[2]{%
% #1 = main part, #2 = subdescriptor
\begin{array}[t]{@{}c@{}}
#1 \\
\noalign{\vspace{-0.6ex}}
\hidewidth \scriptstyle\uparrow \hidewidth \\
\noalign{\vspace{-0.3ex}}
\hidewidth #2 \hidewidth
\end{array}%
}
\begin{document}
\[
0 = x^3 - \subdesc{4}{p}x^3 + \subdesc{3}{q}
\]
\[
0 = x^3 - \subdesc{4}{a}x^3 + \subdesc{3}{b}
\]
\[
0 = x^3 - \subdesc{4}{u-v}x^3 + \subdesc{3}{b}
\]
\end{document}
The arrow is in \scriptstyle
to make it less prominent, but this requires fixing a bit the vertical spacing.