In this specific case, the following answers both your concerns:
- Use
%
at the end of each \stackrel
to avoid a spurious space inserted by the new line (or carriage return) from your editor (you may only want to insert these between the entries you want to "keep together");
- Use
\strut
in each element to raise the contents to a common level. Note that \strut
, defines as \rule[-.3\baselineskip]{0pt}{\baselineskip}
, accommodates for regular character descenders by virtue of a large enough depth and height.
\documentclass{article}
\usepackage{stackrel}% http://ctan.org/pkg/stackrel
\begin{document}
$\stackrel[\strut\textrm{3}]{\strut\textrm{1}}{\strut\textrm{2}}$
$\stackrel[\strut\textrm{sand}]{\strut\textrm{A}}{\strut\textrm{B}}$%
$\stackrel[\strut\textrm{wiches.}]{\strut\textrm{C}}{\strut\textrm{D}}$%
$\stackrel[\strut\textrm{E}]{\strut\textrm{rain}}{\strut\textrm{F}}$%
$\stackrel[\strut\textrm{G}]{\strut\textrm{cloud}}{\strut\textrm{H}}$%
$\stackrel[\strut\textrm{I}]{\strut\textrm{J}}{\strut\textrm{snow}}$%
$\stackrel[\strut\textrm{K}]{\strut\textrm{L}}{\strut\textrm{shoe}}$
$\stackrel[\strut\textrm{jones}]{\strut\textrm{M}}{\strut\textrm{N}}$%
$\stackrel[\strut\textrm{soda}]{\strut\textrm{O}}{\strut\textrm{P}}$%
$\stackrel[\strut\textrm{Q}]{\strut\textrm{yams}}{\strut\textrm{R}}$%
$\stackrel[\strut\textrm{S}]{\strut\textrm{yummy}}{\strut\textrm{T}}$%
$\stackrel[\strut\textrm{U}]{\strut\textrm{V}}{\strut\textrm{gummy}}$%
$\stackrel[\strut\textrm{W}]{\strut\textrm{X}}{\strut\textrm{bears}}$
$\stackrel[\strut\textrm{3}]{\strut\textrm{1}}{\strut\textrm{2}}$
\end{document}
An alternative, instead of using \stackrel
, could just be to insert the contents in a tabular
via a macro. Then the (vertical) alignment should be established by default. Here's a minimal example showing how that can be achieved:
\documentclass{article}
\newcommand{\stackitem}[3]{%
\begin{tabular}{@{}c@{}}#1\\#2\\#3\end{tabular}%
}
\begin{document}
\stackitem{A}{B}{sand}%
\stackitem{C}{D}{wiches.}%
\stackitem{rain}{F}{E}%
\stackitem{cloud}{H}{G}%
\stackitem{J}{snow}{I}%
\stackitem{L}{shoe}{K}
\end{document}
You'll notice that this provides the \stackrel
functionality in a more convenient form since the order of the specified items follow the sequence they're displayed (left-to-right -> top-down). Also, it doesn't require the mathmode-textmode switching.
If you're interested in a more spread out display, that is easily obtainable by using, for example,
\renewcommand{\arraystretch}{2}%
which stretches out the rows by a factor of 2.
Just overlap the symbol with the hat with the slashed version of itself.
\documentclass{standalone}
\usepackage{mathtools,slashed}
\newcommand\hatslashed[1]{{\hat{#1}\mathllap{\slashed{#1}}}}
\begin{document}
$\hat{\slashed{D}}$
$\slashed{\hat{D}}$
$\hatslashed{D}_{\hatslashed{D}_{\hatslashed{D}}}$
\end{document}
You can use \phantom
in the following way to prevent double striking the glyph, but AFAIK \phantom
doesn't detect cramped style and shifts the hat to the right.
\newcommand\hatslashed[1]{{\hat{\phantom{#1}}\mathllap{\slashed{#1}}}}
Best Answer
For the vertical spacing you can use
\raisebox{<amount>}{<content>}
to raise or lower (negative amount) the content. The horizontal centering was already shown for the similar question Overlay symbol with another, which might need a little adjustment here:Here my suggestion. It works in the shown tests in all the different math modes.
Update:
I just remembered that
amsmath
s\text
can be used for math style depending scaling. It already uses similar code as the one above. This simplifies the macro to: