4

The following minimal code

\documentclass{article}

\usepackage{amsmath}
\usepackage{tikz}

\newcommand*\mycircb[1]{%
  \tikz[baseline=-1.5pt]\node[draw,circle,inner sep=0.8pt, scale=0.8] 
  {\upshape \footnotesize \textbf{#1}};\!\!
}
\newcommand*\Swtch[3]{%
    \xrightarrow[{\text{\mycircb{#2} $>$ \mycircb{#3}}}]{\text{#1}} 
}

\begin{document}
\[
\Swtch{Boo}{A}{B}
\]
\end{document}

produces the following picture

Picture

There is a little bit too much vertical spacing below the arrow. How do I make the 'denominator' move closer to the dividing arrow? I'm looking for something like a negative \vphantom command. Similarly, suppose I wanted to adjust the 'numerator' spacing. Space can be added by using \vphantom, but how can space be removed?

TSGM
  • 2,342

3 Answers3

6

Instead of using \vphantom you could use \settoheight{\yourlengthcmd}{text} to get the height of the argument and apply this as negative space.

Stefan Kottwitz
  • 231,401
4

Try this:

\newcommand*{\Swtch}[3]{%
  \mathrel{\vcenter{\offinterlineskip%
  \hbox{\phantom{\,\mycircb{#2}}{\scriptsize#1}}\vskip-0.4ex\hbox{\ensuremath{\xrightarrow[\hphantom{\text{\mycircb{#2} $>$ \mycircb{#3}}}]{}}}\vskip-1.8ex\hbox{\,\text{\mycircb{#2} $>$ \mycircb{#3}}}}}%
}

The first \phantom and the two uses of \, is a bit of a hack used to center the text, but should be what you are looking for. You can adjust the amount of space by changing the parameters to the two \vskip.

Here is the comparison:

enter image description here

Peter Grill
  • 223,288
  • Yes, I simple \vskip or \vspace with a negative (or positive) value should be used for such cases. I have the feeling that the OP only knows about \vphantom. – Martin Scharrer Aug 04 '11 at 09:00
  • Complicated, but interesting. I decided to accept this answer, as it seems the most flexible (as opposed to the \smash command). Thanks. – TSGM Aug 04 '11 at 17:30
3

You can use \smash:

\documentclass{article}

\usepackage{amsmath}
\usepackage{tikz}

\newcommand*\mycircb[1]{%
  \tikz[baseline=-1.5pt]\node[draw,circle,inner sep=0.8pt, scale=0.8]
  {\upshape \footnotesize \textbf{#1}};\!\!
}
\newcommand*\Swtch[3]{%
    \xrightarrow[{\text{\mycircb{#2} $>$ \mycircb{#3}}}]{\text{#1}}
}

\newcommand*\Swtchnew[3]{%
    \xrightarrow[\smash{\text{\mycircb{#2} $>$ \mycircb{#3}}}]{\text{#1}}
}

\begin{document}
\[
\Swtch{Boo}{A}{B}  \Swtchnew{Boo}{A}{B}
\]
\end{document}

\xarrowright with \smash

Werner
  • 603,163
Ulrike Fischer
  • 327,261