I'm having trouble getting the desired alignment behavior in a set of "sets" that I'm typesetting. I have a bunch of set definitions of the form

$$U = \{\text{$x$ $|$ $x$ satisfies some condition}\}$$

Of course, I want the equals signs to line up, which is easy enough to do with an align* environment.

The problem is that for some of the sets, the "some condition" takes a couple of lines to state. I'd like like those lines to align after the | symbol. Of course, if I only had one set to define, then I could do the previous thing with the align* environment.

However, I want to achieve both of the above behaviors in the same set of equations. How do I do this?

EDIT: After seeing frabjous's answer below, I realized that I didn't emphasize (or even mention) one of the key difficulties. The U's and x's in my set definition are actually expressions with different lengths, so the second align point in each set definition is different. This prevents me from using an array environment. For instance, I could have something like the following:

X = {(p,q) | p=q+7 and something else very long that doesn't fit
on one line}

Y(1) = {x | x is prime}

Z' = {(a,b,c) | the variables a, b, and c satisfy a condition that
is too long for one line}.

Sorry for not using tex in the above, but I think it makes it clear what is happening.

Thanks for any help.

EDIT 2: Thanks to Antal S-Z's nice answer, I was able to create a macro that does exactly what I wanted. In case anyone desires the same behavior, here it is.

\newcommand\Set[3]{\ensuremath{\{\text{#1 $|$ \parbox[t]{\widthof{#3}}{#2\}}}}}

You call it with 3 arguments. To get a set {x|P}, the first argument should be x, the second P (with newlines in it) and the third the longest line in your condition P. This is compatible with align*, so you can then do things like

A &= \Set{x}{P}{Q}\\
B &= \Set{y}{R}{S}

and it typesets things correctly.


I'd do this with an alignat* environment, but just put the text inside a parbox. That way, you can just align every equals sign and vertical bar; the line breaking will leave the text after the bar in ever case. This works, but is unfortunately slightly complicated. The best way to typeset a set comprehension (using etex) is with something like \left\{ x \;\middle|\; \phi \right\}1,2, but apparently you can't put an & between a \left and a \right. Manual scaling works, though, which gives this solution:

\newcommand{\pctext}[2]{\text{\parbox{#1}{\centering #2}}}
  X    &= \biggl\{(p,q)   &&\;\bigg|\; \pctext{1.5in}{$p=q+7$ and something else
                                                      very long}\biggr\} \\
  Y(1) &= \{x             &&\;|\;      \pctext{1.5in}{$x$ is prime}\} \\
  Z'   &= \Biggl\{(a,b,c) &&\;\Bigg|\; \pctext{1.5in}{the variables $a$, $b$,
                                                      and $c$ satisfy a
                                                      condition that is too long
                                                      for one line}\Biggr\} \\

This gives the following output:

Multiply aligned set comprehensions.

As you can see, this does work, though I think it's not ideal. There are some spacing issues (which I'm not sure how to fix, or even what best to do) stemming from the differing sizes of the braces. And the code's a bit cluttered; one could probably write a macro to abstract some of the boilerplate, but enclosing & in macros with align and friends tends to be problematic.

1: Actually, I typically use the braket package to write \Set{x | \phi}, but it uses \left and \right (and \middle if it can) under the hood.

2: Since it's assumed that | is a delimiter here, it's not spaced out, and so we use \;s to get the spacing right. If we use a relation such as \mid, we get the same (I think) spacing, but we can't \middle it.

  • Thank you very much! This wasn't exactly what I was looking for, but I was able to adapt it to get what I needed (and I edited the question to add my solution). – Andy Putman Dec 21 '10 at 7:07
  • 1
    @Andy: I guess that it would be even better if you add your solution in a new answer; you can then even accept your own answer. (Antal will lose 15 points when you "unaccept" his answer, but as an intro to your own answer you can write that it's based on Antal's answer and ask people to upvote that answer.) – Hendrik Vogt Dec 21 '10 at 8:32
  • @Andy: Feel free to do what Hendrik said; correctness is more important than reputation :-) Also, as an additional note, you can simplify your macro by using the pbox package; I often define \newcommand{\Pbox}[2][]{\pbox[#1]{\textwidth}{#2}}, so that \Pbox{...} produces a minimum-width box. It doesn't work with \centering, but if you don't want your condition centered, it'll allow you to get rid of your third argument to \Set. – Antal Spector-Zabusky Dec 21 '10 at 9:07

You could use an array environment (or perhaps alignat). Something like:

 U &= x \mid &x \text{ satisfies some condition that}\\ 
   &         &\text{takes a long long time to state}\\
 V &= y \mid &y \text{ satisfies something else}

It's also possible you really should use a cases environment for conditional definitions.

Note: you should not use $$ ... $$ for displayed math. It is considered obsolete. For further explanation, see l2tabu.

  • Thanks! The problem is that the "x"'s have different lengths, so the second align points should be different in different set definitions. I'll amend the question to make this clearer. – Andy Putman Dec 21 '10 at 5:13

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.