4

I have a list of equations with annotations like the one below:

\documentclass{scrartcl}
\usepackage{amsmath}
\begin{document}
\begin{align*}
  aaaa &= 1  &&\text{for $X$} \\
  bbbb &= 1  &&\text{for $Y$} \\
  c    &= 1  &&\text{for $Z$} \\
  d    &= 12 &&\text{for $Z$}
\end{align*}
\end{document}

Since the last two lines have the same annotation, I'd like to add a brace there and put the annotation next to the brace. I know that I can do that like this:

\documentclass{scrartcl}
\usepackage{amsmath}
\begin{document}
\begin{align*}
  \left. \begin{aligned}
    c &= 1 \\
    d &= 12 \\
  \end{aligned} \right\} &&\text{for $Z$}
\end{align*}
\end{document}

But how to join the two? The last two lines will only be aligned among themselves, not with the first two. Is there a way out of this?

Thanks in advance.

David Carlisle
  • 757,742
anonymous
  • 1,159

1 Answers1

3

Here is a naive attempt at positioning braces in align:

enter image description here

\documentclass{scrartcl}% http://ctan.org/pkg/koma-script
\usepackage{amsmath}% http://ctan.org/pkg/amsmath
\begin{document}
\begin{align*}
  aaaa &= 1  &&\text{for $X$} \\
  bbbb &= 1  &&\text{for $Y$} \\
  c    &= 1  && \\
  d    &= 12 &&\llap{\smash{\raisebox{\dimexpr.5\normalbaselineskip+.5\jot}{$\left.\begin{array}{c}\null\\[\jot]\null\end{array}\right\}\quad$}}}
      \text{\smash{\raisebox{\dimexpr.5\normalbaselineskip+.5\jot}{for $Z$}}}
\end{align*}
\end{document}

The combination of \smash (removing any vertical height), \raisebox (for vertical movement) and \llap (removing horizontal width using a left overlap) allows for manipulating the position of the brace.

Of course, the (horizontal) location of the brace can be adjusted.

Werner
  • 603,163
  • So \smash{\raisebox{\dimexpr.5\normalbaselineskip+.5\jot}{<content>}} is an idiom for positioning something centered between two lines. On top of that, \left.\begin{array}{c}\null\\[\jot]\null\end{array}\right\} creates a brace of the right height through an empty array of the right height, if I understand correctly. Is there no easier way to create some kind of phantom of the right height? The array seems a bit scary in there :) – anonymous Aug 22 '12 at 07:42
  • (Sorry, I have to ask): If I replace the align* environment with an align environment, the last line will now get two numbers. Is there a way around that? – anonymous Aug 22 '12 at 07:55
  • @anonymous: There are other ways of doing this; not sure whether they would be considered easier though. You can use \nonumber on every line where you want to suppress the equation number. However, using your setup, this will not work since the number will be aligned with the equations, not the "descriptors" (the "for ..." part). Then you need to consider something else, which might require a different solution. Perhaps consider asking a follow-up question. – Werner Aug 22 '12 at 14:31
  • I've now asked the follow-up question http://tex.stackexchange.com/questions/68547/alignment-across-nested-aligned-environments – anonymous Aug 24 '12 at 07:38
  • Can an align environment be nested inside another align environment? – Royi Jun 10 '17 at 13:51
  • @Royi: Have you tried it? There are ways around multiple alignments that doesn't require a nested align. – Werner Jun 10 '17 at 17:32
  • But just to know, is it OK to use 'align' inside 'align'? – Royi Jun 10 '17 at 18:48
  • @Royi: It's okay, but it doesn't work. ;) As I said before, if you're interested in multiple alignments, there are other options that doesn't require nesting. – Werner Jun 10 '17 at 18:51