4

I am trying to do the following: enter image description here

where I want to draw the up and down arrows within text. I first assumed it to be tikz, so below is my MWE. It is weirdly shifted up a little bit, so please help me recreate the above example of arrows.

\newcommand{\upspin}{\tikz[scale=0.5]{\draw[-Latex] (0,0) -- (0,0.6cm);}}
This is the spin-up (\upspin) electron and the spin-down (\dspin).

Please let me know.

1
  • 6
    please provide a test document and not just a fragment, but why tikz rather than $\uparrow$ ? Nov 28 '21 at 23:06
6

With option \tikz[baseline=<length>] and relative length unit em:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{arrows.meta}
\usepackage{lipsum}

\newcommand{\upspin}{%
  \tikz[baseline=.2em] \draw[-Latex] (0,0) -- (0,1em);}
\newcommand{\dspin}{%
  \tikz[baseline=.2em] \draw[Latex-] (0,0) -- (0,1em);}

\begin{document}
\lipsum*[1][1-3]
This is the spin-up (\upspin) electron and the spin-down (\dspin).
\lipsum*[1][1-3]
\end{document}

enter image description here

PS: You can search for [tikz] baseline on this site or in the pgfmanual to learn more about this option.

Update: Following hpekristiansen's suggestion, a revised version using ex unit. Note the used depth and height setting may not work for all fonts.

One could, of course measure the height and depth of ( in text mode and use them in \upspin and \dspin, and even insert the measuring code in latex2e hook selectfont (\AddToHook{selectfont}{...}) for efficiency concerns.

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{arrows.meta}
\usepackage{lipsum}

\newcommand{\upspin}{%
  % depth = .5ex, height = 1.75ex
  \smash{\tikz[baseline=0pt] \draw[-Latex] (0,-.5ex) -- (0,1.75ex);}}
\newcommand{\dspin}{%
  \smash{\tikz[baseline=0pt] \draw[Latex-] (0,-.5ex) -- (0,1.75ex);}}

\begin{document}
\lipsum*[1][1-3]
This is the spin-up (\upspin) electron and the spin-down (\dspin).
\lipsum*[1][1-3]
\end{document}

enter image description here

3
  • Would ex not be a better unit here (I do not know the convention, or if it matters)? Nov 28 '21 at 23:59
  • @hpekristiansen Yes ex unit is better, though with ex you still need to try for an appropriate multiple (1ex is not tall enough). The height and depth of \mathstrut seems even better. Nov 29 '21 at 0:11
  • Hmm, in usage (\upspin) curly braces are in text mode. So \baselineskip and \f@size pt is safer, maybe even with \smash{\tikz ...;}. I mean, a guessed max allowed height and depth in normal text line is, hard to work everywhere. Nov 29 '21 at 0:16

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.