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.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

There I was, a-merrily tracing through the depths of beamer's code on the trail of the Dreaded Overprint Hurler of Bexhill-on-Sea, when I came across Something Completely Different. It looked like a cross between a vbox and a centering, but horribly, horribly mutated.

Desiring to slay this monstrous beastie before it could wreak havoc, I studied it and its relatives (from a safe distance). Its behaviour is strange, but by caging it I could see some patterns in its responses to basic stimuli. Eventually, I realised that if I could but introduce some genetic mutation which temporarily switched off the \centering gene then it could be made safe and I could resume my quest to track down the Overprint.

In less prosaic language, while investigating Overprint environment inside tikz node: unexpected alignment of content I figured out that the problem was due to the interaction between the center environment (aka \centering) and how beamer implements the overprint environment. What beamer does is gather all the possible versions of the overprint environment into vboxes containing minipages of the prescribed width. It then sets the correct one (according to the overlay specification) but with the height and depth of the biggest one. However, if the overprint environment is contained within a center environment, something a little odd ensues. It would appear that the vbox containing the minipage environment has already taken into account the center environment and so consists of the minipage environment at the centre of the line, with the requisite spacing fore (and presumably aft). But when the vbox is set, it is still within the center environment so picks up a new indentation. This wouldn't matter, except for the fact that the vbox's width is adjusted to the prescribed width so TeX adds yet more horizontal space to shove the vbox back into the centre of the line (or so it thinks).

Given that all of this is going on inside a beamer overprint environment, and I don't want to muck around with that code, the simplest solution seemed to be to turn off the \centering just before the overprint environment (and, given my reading of the original question, turn it back on again inside). But \centering seems to be a one-way trap: there's \centering, \rightragged, \leftragged, but no \backtonormal.

Here's some code to play around with:











\setbox\mybox=\vbox\bgroup\fbox{\begin{minipage}{4cm}\centering hello



\fbox{\begin{minipage}{4cm}hello world\end{minipage}}

\fbox{\begin{minipage}{4cm}\centering hello world\end{minipage}}


Here's what I get from that:

boxes and centring and alignment

share|improve this question
The package ragged2e provides \justifying – egreg Jun 25 '12 at 13:24
editorial niggle -- the first section is "less prosaic", i.e., purple; the second section is the "more prosaic" (dictionary definition: "humdrum") version. now, if you'd said "poetic", ... beware the jabberwock, my son. – barbara beeton Jun 25 '12 at 16:57
@barbarabeeton You have a choice of responses. Press "1" for "I put that in just so that you'd leave an editorial comment.". Press "2" for "I was being ironic. (I am British, after all).". Press "3" for "I'd've gotten away with it too if it weren't for you pesky AMS staff.". Press "9" for English. – Loop Space Jun 25 '12 at 18:22
how about "4" for "the pesky tugboat editor just won't let anybody get away with anything, no matter how trivial." – barbara beeton Jun 25 '12 at 19:18
@barbarabeeton Wasn't that "3"? s/AMS/tugboat/. – Loop Space Jun 25 '12 at 19:42
up vote 9 down vote accepted

The package ragged2e provides enhanced versions of \centering, \raggedright and \raggedleft (that you may or may not like), but above all makes available the command


that undoes the above declarations.

share|improve this answer
I think this one should be at the top for sheer "ease of use". Whilst I tend to go for the more hackish solutions, I suspect that others wanting the same feature would be best served by the ragged2e package. Hence I'm accepting this one, though all were useful solutions. – Loop Space Jun 26 '12 at 8:28
  \let\\\@centercr\rightskip\z@skip \leftskip\z@skip%
  \parfillskip=0pt plus 1fil}



enter image description here

If you need a parindent then set it in the definition.

share|improve this answer
In the question where I got this from, I got some Underful hboxes until I put \parfillskip=0pt plus 1fil. I also don't understand why the double backslash is let to \@centercr. Isn't that what it already is (from the \centering)? – Loop Space Jun 25 '12 at 12:27
yes, you're right if you have \centering before – Herbert Jun 25 '12 at 12:38
So wouldn't I want to let it back to whatever-it-normally-is? (which, I find, is different in beamer as there whatever-it-normally-is is the same as \@centercr) – Loop Space Jun 25 '12 at 12:42
Shouldn't it be \parfillskip=0pt plus 1fil? – egreg Jun 25 '12 at 13:26

since you are in a box already (so page breaking isn't a concern) can't you just do


centering a full width box is a no-op and the text inside the box will be justified.

share|improve this answer
That works, but it took me a while to figure out why. I thought that that ought to put a vertical box of width \textwidth at the corresponding location (which would be bad), but it doesn't. The reason seems to be because overprint puts its stuff in a vertical box. If I force a horizontal box in there somewhere then the inner box ends up being \textwidth and so the resulting box is too wide. – Loop Space Jun 25 '12 at 12:15

Your Answer


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.