6

I hope that the following question is not a duplicate but I could not find a definite answer.

I'm trying to obtain the the same result as Formula (1) in the picture next, but I feel that my approach is not optimal and somewhat dirty.

enter image description here

I produced the output with the following code:

\documentclass{scrartcl}

\usepackage{amsmath}

\begin{document}

\begin{equation}
\begin{aligned}
X & = \{ x \mid \text{a very very very long condition} \} \cup \\
  & \phantom{{}={}} \{ y \mid \text{another very very very long condition} \}
\end{aligned}
\end{equation}

\begin{equation}
\begin{split}
X & = \{ x \mid \text{a very very very long condition} \} \cup \\
& \quad \{ y \mid \text{another very very very long condition} \}
\end{split}
\end{equation}

\begin{equation}
\begin{aligned}
X = & \{ x \mid \text{a very very very long condition} \} \cup \\
  & \{ y \mid \text{another very very very long condition} \}
\end{aligned}
\end{equation}

\begin{equation}
X = 
\begin{array}[t]{l}
  \{ x \mid \text{a very very very long condition} \} \cup \\
  \{ y \mid \text{another very very very long condition} \}
\end{array}
\end{equation}

\end{document}

Formula (1) is the output I desire. However, I can't imagine that using \phantom is the right way to go.

Formula (2) is according to the examples in the amsmath package documentation. And it looks ugly.

Formula (3) is better, but the kerning is wrong. However, I somehow feel that using the alignment in this way is the right approach.

Finally, Formula (4) uses an array, but also here the kerning is screwed.

Can anyone hint me in the right direction? Thanx!

7
  • 1
    The right way to write it inside aligned is: \begin{aligned} X = {} & \{ x \mid \text{a very very very long condition} \} \cup \\ & \{ y \mid \text{another very very very long condition} \} \end{aligned} Aug 12, 2013 at 20:19
  • I would agree that #3 is the idiomatic way, but I don't see the issue with kerning that you see, I suppose. At least in the picture, it's unnoticeable (to the point that I don't see it at all). Aug 12, 2013 at 20:19
  • @SeanAllred -- take a closer look. in #3 there is no space between the equals sign and what follows. this is wrong. only #1 has the desired (proper) spacing. Aug 12, 2013 at 20:28
  • @barbarabeeton oh goodness, how did I miss that? Well, using \phantom isn't all that hacky---this might be legitimate use. (For laziness' sake, something tells me you can add an empty group after = in #3 to achieve the effect---it's less typing.) Aug 12, 2013 at 20:36
  • 1
    @karlkoeller perhaps an answer then? :-) Aug 12, 2013 at 20:40

1 Answer 1

7

In these cases there is no need at all for \phantom commands.

To ensure the correct spacing when binary relations or operators are involved, it suffices to use an empty group {}.

Infact, the code

\documentclass{scrartcl}
\usepackage{amsmath}

\begin{document}

\begin{equation}
\begin{aligned}
X  = {} & \{ x \mid \text{a very very very long condition} \} \cup {} \\            
        & \{ y \mid \text{another very very very long condition} \}
\end{aligned}
\end{equation}

\end{document} 

gives the desired spacing:

enter image description here

2
  • Thanks, this solution gives the right output and "feels right" ;) I guess that I should also use \cup {} \\ rather than just \cup \\ to get a proper spacing?!
    – Dan
    Aug 12, 2013 at 20:58
  • @Dan Sorry, I've been notified about your original comment, so I didn't see the edit. The answer is: yes, of course (I was going to bed and I didn't even notice that the first line ends with \cup...). I've added it in the answer, too. Aug 13, 2013 at 6:34

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .