In question 83509, a way of getting \hfill-like behaviour in the align environment is described, but for my purposes, I need one that works in the equation environment. (I want to display some commutative diagrams next to each other, but for some reason, tikzcd does not like being inside align.)

  1. Why does TeX ignore \hfill inside displayed mathematics?
  2. How can this be worked around?

I suppose I could in principle just put the various blocks inside $...$, but for consistency, it would be probably be better to have all displayed mathematics in equation or similar environments.


You can force things to stretch by giving them a large natural width and allowing them to shrink, rather than \hfill which has a natural width of 0pt.


$$a\hskip \textwidth minus \textwidth b$$


enter image description here

But a CD package is almost certainly making a box anyway so placing them inside a display math environment probably doesn't achieve much, however if you mean what I think you mean then putting shrinkable glue between two boxes will force them apart as shown here.

  • The tikzpicture environment (and by extension tikzcd) is, for some strange reason, typeset inline. I always enclose it in \[ ... \] to make sure it is displayed like other bits of maths. – Zhen Lin Apr 29 '13 at 20:47
  • Your solution seems to meet the requirements, thanks! But I'm all the more puzzled: isn't \hfill also internally implemented as a kind of \hskip? – Zhen Lin Apr 29 '13 at 20:50
  • 3
    @ZhenLin \hfill is \hskip 0pt plus 1fill so it has a natural width of 0pt and just stretches if needed. the skip I used has a natural size of \textwidth and shrinks if needed. When setting a display math TeX is centering it internally so almost never needs to stretch glue so \hfill doesn't stretch,but it needs to shrink this glue so it shrinks by the minimum amount required to make the whole display fit so forces the items apart as far as possible. – David Carlisle Apr 29 '13 at 20:58
  • @ZhenLin It's not strange, since one might be producing a very small image to appear inline. For example, as a special symbol. More abstractly, it keeps your options open, whereas there is no way to un-display something. – Ryan Reich Apr 29 '13 at 21:50

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.