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.

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.

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?
  • 1
    This question might be interesting for you. – percusse Apr 4 '12 at 8:50
  • You can play with \llap, though it's not a solution, just a workaround. – Marco Apr 4 '12 at 10:06
  • @Marco: why not define \clap? I wrote a short answer with this idea. – mbork Apr 4 '12 at 10:42
  • You can also look at the ruby module by Wolfgang Schuster. – Aditya Apr 4 '12 at 21:16

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

  • 3
    IMO it makes sense to include a \strut, otherwise the overtext almost always appears too close to the main text. – Marco Apr 4 '12 at 10:53
  • @Marco: good point, I've included it in my answer. – mbork Apr 4 '12 at 14:50
  • ConTeXt already has a \clap command (that works correctly both in text and math mode). – Aditya Apr 4 '12 at 21:13
  • @Aditya: oops, I didn't know that. I've updated my answer. – mbork Apr 5 '12 at 6:10

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} 
  • 6
    Welcome to TeX.SX! The question is about ConTeXt, which hasn't \makebox. – egreg Oct 21 '13 at 9:30
  • useful anyway... I'm using LaTeX and that's what I was looking for :) – Stéphane Laurent May 28 '14 at 14:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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