Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I have several \stackrel's in my document. See the e.g.:

\documentclass{article}
\usepackage{stackrel}
\begin{document}
    $\stackrel[\textrm{sand}]{\textrm{A}}{\textrm{B}}$
    $\stackrel[\textrm{wiches.}]{\textrm{C}}{\textrm{D}}$
    $\stackrel[\textrm{E}]{\textrm{rain}}{\textrm{F}}$
    $\stackrel[\textrm{G}]{\textrm{cloud}}{\textrm{H}}$
    $\stackrel[\textrm{I}]{\textrm{J}}{\textrm{snow}}$
    $\stackrel[\textrm{K}]{\textrm{L}}{\textrm{shoe}}$
\end{document}
  • How can I adjust the horizontal spaces between each \stackrel such that the longest items from each stackrel are spaced as if they are from the same word (i.e. "sand wich" will appear exactly the same as a typeset "sandwich")?
  • How can I adjust the vertical spaces between each layer of the \stackrel's line up (i.e. A, C, rain, cloud, J, and L all appear on the same line)?

Updates:

  • (With the above) how can I ensure that lower-case letters with descenders, "q", "y", "p", and "j" still descend properly?
share|improve this question

1 Answer 1

up vote 4 down vote accepted

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.

enter image description here

\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:

enter image description here

\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.

share|improve this answer
    
The first (\stackrel) solution presents a new problem: if there are many \stackrel's, the document does not know when to break the line, so they run off the edge of the page. The second (tabular) solution will probably introduce too many other problems into my document. –  Village Nov 16 '11 at 6:53
    
Inconvenience aside, is there any reason I should avoid mathmod-textmode switching? Does this create does anomalies within typography? –  Village Nov 16 '11 at 6:53
    
What kind of "other problems" would the tabular approach introduce? Switching to/from math/text is not necessary in this case, and removes from your code readability. It seems like you're using the stackrel package just because it provides the stacking functionality while other, more suitable, alternatives exist. –  Werner Nov 16 '11 at 7:26
    
Yes, I use stackrel only because it allows 3 levels of text. The stacks sometimes appear within the table of contents and inside \section titles and sometimes contain \footnote's, \glossary entries, cross-references of various kinds, etc. –  Village Nov 16 '11 at 7:38
    
I discovered a problem with strut used together with stackrel: if the word at the top has a lower-case "y", "p", "g", or "j" (which normally hang down below the line), then these words are pushed up. In other words, the bottom of "j" in "jump" will appear at the same hieght as the bottom of "z" in "zebra". –  Village Nov 22 '11 at 0:00

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.