3

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?
Village
  • 13,603
  • 23
  • 116
  • 219

1 Answers1

4

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.

Werner
  • 603,163
  • 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 06: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 06: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 07: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 07: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 00:00
  • @Village: I've added some additional examples to the \stackrel example in my post. There is no problem with the descenders in that case, since they line up properly across \stackrels, and there is no artificial height adjustments introduced. If this is not the case with your working example, then you need to post more information. – Werner Nov 22 '11 at 00:33
  • Oh, I did not realize it needs the strut's on every level. That pushes text away below and pushes text away above (at each line)? – Village Nov 22 '11 at 01:28
  • @Village: Yes. The idea being that you place a "big enough invisible character" on each line. Did you want something different? – Werner Nov 22 '11 at 02:14
  • No, your solution is very helpful. – Village Nov 22 '11 at 07:17