3

Consider the working example:

\documentclass{article}
\usepackage{amsmath}


\begin{document}
    \begin{align*}
        (a+b)^2 &= a^2 + 2ab + b^2\\
        (a-b)^2 &= a^2 - 2ab + b^2
    \end{align*}
\end{document}

What I need is to draw } at the right hand side that will cover both the lines, follwoed by some text. This image represents what I wanted (given in red).

I don't have a clue on how to get started (so, there is no code that I tried).

2
  • 2
    Seatch this site for solutions using the \tizmark library. That will not only help you get his done but also set you up for solving a lot of similar issues. Multiline brackets within a {description} environment is an answer that shows how to solve a similar requirement for a list environment. Even though it is a different environment the idea is the same: place mark at the approraite points on the page that you can later access and do the drawing. Aug 24 '20 at 4:27
  • There are solutions that work without using \tikzmark as well, but those won't be usable in as many cases as \tikzmark will be and may not be as easy to customize in terms of colors, shading, etc. Aug 24 '20 at 4:29
7

You have two main options: (a) an array environment, and (b) an rcases environment; the latter is provided by the mathtools package. As the following screenshot shows, they produce the same horizontal layout. If you look closely, the line spacing with the rcases option is a bit more generous than it is for array option. The increase in vertical spacing may -- or may not -- be to your liking.

In fact, due to the use of an aligned environment to encase the equations, a third option is available as well: (c) don't use either array or rcases -- \left. \blurb \right\} suffices fully. Many thanks to Donald Arseneau for pointing this out in a comment.

enter image description here

For the case at hand (pun intended), using the rcases environment may be a bit of overkill as the test code doesn't make use of many of the environment's capabilities.

If you need the word "sum" to be typeset in red, be sure to (i) load the xcolor package in the preamble and (ii) change \text{sum} to \text{\color{red}sum}. If the right-hand curly brace also needs to be rendered in red, you can't use the rcases solution ("option B") and you'll need to type \color{red}\right\} and \text{\color{red}sum}.

\documentclass{article}
\usepackage{mathtools} % for 'rcases' environment
\newcommand\blurb{% 
% material that's common to all three options:
    \begin{aligned}
        (a+b)^2 &= a^2 + 2ab + b^2\\
        (a-b)^2 &= a^2 - 2ab + b^2
    \end{aligned}
}
    
\begin{document}
\begin{align*}
%% Option A: 'array' environment
    \left. \begin{array}{@{}c@{}}
       \blurb
    \end{array} \right\}
    &\text{sum} 
    \\[1ex]
%% Option B: 'rcases' environment
    \begin{rcases}
       \blurb
    \end{rcases}
    &\text{sum}
    \\[1ex]
%% Option C: no encasing environment
    \left. 
       \blurb
    \right\}
    &\text{sum} 
\end{align*}
\end{document}
2
  • 1
    What is the array for? You are using aligned already. Making the brace red eliminates rcases. \left. \blurb \color{red}\right\} \text{\color{red}sum}. Aug 24 '20 at 5:15
  • @DonaldArseneau - Many thanks for pointing out that array isn't strictly needed. I've edited the answer to provide the no-array setup (\left. \blurb \right\}) as a third option. I didn't delete the array option entirely as the OP may (or may not)! be interested in getting slightly tighter line spacing.
    – Mico
    Aug 24 '20 at 5:38
4

Still another short way, with empheq (which loads mathtools):

\documentclass{article}
\usepackage{empheq}
\usepackage[svgnames]{xcolor} 

\begin{document}

    \begin{empheq}[right=\color{Coral}\empheqrbrace \textsf{sum}]{align*}
        (a+b)^2 &= a^2 + 2ab + b^2\\
        (a-b)^2 &= a^2 - 2ab + b^2
    \end{empheq}

\end{document} 

enter image description here

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.