8

I am using the \overset and \underset commands in ConTeXt, to place text over other text within a paragraph, e.g.:

(animal)                (animal)   (animal)
 Bears   like to   eat    fish  and snakes.
                (action)

The \overset command successfully places text above, but it also creates spaces in the main text, as shown above. I would prefer it the main text has normal spacing when possible, e.g.:

(animal)         (animal)   (animal)
 Bears like to eat fish and rabbits.
            (action)

Only in situations where two \oversets or \undersets appears next to each other and require more space than the regular text should extra spacing be added, e.g.:

(animal) (animal)   (animal)
 Bears,    fish, and frogs  eat,    play, and swim in the river.
                         (action) (action)  (action)
  • How can I condense the spacing around text when \oversets and \undersets are used, to the extent that is possible?
Village
  • 13,603
  • 23
  • 116
  • 219

2 Answers2

8

Here's a plain TeX solution (which, as Aditya mentioned, is already implemented in ConTeXt, even in a better, math-mode-compliant way)::

\def\clap#1{\hbox to 0pt{\hss #1\hss}}

Now \clap{whatever} sets whatever as if it had zero width, centered horizontally around the point it was encountered by TeX.

(Obviously, this macro follows the idea of \llap and \rlap.)

Of course this won't help when oversets etc. overlap.

Edit: as Marco pointed out in the comment, this might be better idea:

\def\clap#1{\hbox to 0pt{\hss\strut #1\hss}}

The \strut macro makes the \clap box as high (and deep) as the "highest/deepest" character in the font (at least in theory - but unless the settings are very weird, this should work).

mbork
  • 13,385
1

The simplest solution is to use a zero-with box \makebox[0pt]{} around the text you want either under or over. e.g.,

\overset{\makebox[0pt]{(\scriptsize animal)}}{Bears}