5

I want a series of aligned equations, the last of which has two cases. See the figure for an example.

enter image description here

\documentclass{article}
\usepackage{amsmath}
\begin{document}
\begin{align*}
    a &= b \\
&\begin{cases}
    \ge c \\
    \le d
\end{cases}
\end{align*}
\end{document}

Naturally, I want the =// signs to be aligned.

This issue crops up quite often in my work. I always have to come up with some rather hacky, non-generalisable way using \mathllap{\Bigg\{}. But, it's rather unsatisfying to hack it each time—and the hack won't work on many scenarios—so I wonder if there is a better, more direct way?

4
  • What is the use of this?
    – projetmbc
    Jan 18, 2023 at 16:16
  • 1
    @projetmbc I want to bound something, call is a, above an below. However, it's not obvious how to do this. I first do a manipulation, writting it as b, say. Now, it is easy to see how to bound b above and below, say by c and d respectively :)
    – Sam OT
    Jan 19, 2023 at 9:21
  • 1
    If I would see this, I would not understand what was meant. Why not just say $a=b, c \le b \le d$? Not answering the literal question, so posted as comment.
    – user132647
    Jan 19, 2023 at 9:43
  • 1
    @user132647 Fair enough, thanks for the feedback! What you write, unfortunately, would look fairly horrendous with large expressions. The other option, of course, is $a = b \in [c, d]$. But, again, this doesn't look so good with large expressions. I'll have a think about how to improve it 👍
    – Sam OT
    Jan 19, 2023 at 13:20

5 Answers 5

8

You could use the nicematrix package as shown in https://tex.stackexchange.com/a/583373/36296

\documentclass{article}
\usepackage{nicematrix}
\begin{document}

\[
\begin{NiceArray}{r@{\;}l}[first-row]
a&= b \\ 
&\ge c\\
&\le d
\CodeAfter \SubMatrix{\{}{1-2}{2-2}{.}[left-xshift=0.1em]
\end{NiceArray}
\]

\end{document}

enter image description here

5
  • You might want \; instead of \ to get the correct spacing between a and =.
    – Sandy G
    Jan 18, 2023 at 15:44
  • @SandyG Thanks! Fixed Jan 18, 2023 at 15:48
  • Such a beautiful suggestion
    – MadyYuvi
    Jan 18, 2023 at 16:26
  • @MadyYuvi <3 Thanks! Jan 18, 2023 at 16:28
  • 1
    This is a nice package, +1! I do prefer not to use packages, where a simple answer is possible. But, it seems that a simple answer isn't possible in this case! The package seems like a good one to know about for other scenarios, too
    – Sam OT
    Jan 19, 2023 at 9:20
6

Adaptations

  • insert a negative space before the cases environment: \hspace{-.73em}
  • use relative size em, so it works ok (not perfectly, as there is a small difference for huge) also for other fontsizes
  • I defined an environment alignedcases for this. This way it is easier to type and you could change it later on, if you find a better solution.
\newenvironment{alignedcases}{
    \hspace{-.73em}
    \begin{cases}
}{
    \end{cases}
}

Result

enter image description here

Code

\documentclass{article}
\usepackage{amsmath}
\usepackage{tikz}
\usetikzlibrary{tikzmark}

\newenvironment{alignedcases}{
    \hspace{-.73em}
    \begin{cases}
}{
    \end{cases}
}

\newcommand{\test}[1]{
    \begin{align*}
        a &\tikzmark{#1}= b \\
        &\begin{alignedcases}
            \ge c \\
            \le d
        \end{alignedcases}
    \end{align*}
    %
    \begin{tikzpicture}[overlay, remember picture]
        \draw [red] ([xshift=.31em, yshift=.75em] {pic cs:#1}) -- ++(0,-4.5em);
    \end{tikzpicture}
}


\begin{document}

\footnotesize\test{footnotesize}
\small\test{small}
\normalsize\test{normalsize}
\large\test{large}
\LARGE\test{LARGE}
\huge\test{huge}

\end{document}
1
  • 1
    This is nice, thanks. I didn't really want to manually guess what negative hspace works. I thought there might be some nicer method. But, as you show with the red marks, what you have is really undiscernibly different
    – Sam OT
    Jan 19, 2023 at 9:16
3

It's tricky:

\documentclass{article}
\usepackage{amsmath}
\begin{document}
    \begin{align*}
        a &= b \\
        &\hspace*{-.2cm}\begin{cases}
            \ge c \\
            \le d
        \end{cases}
    \end{align*}
\end{document}

... but works:

enter image description here

3
  • This doesn't look correctly aligned to me. See @dexteritas's answer
    – Sam OT
    Jan 19, 2023 at 9:15
  • I posted a way to have alignement. I tryed different negative values and post one of these. The post of @dexteritas follow the same way (after me) but with one better value. That means that if I change '-.2cm' in my answer with '-.73em', my answer work perfecly, but with a better (even perfect) alignement. Jan 19, 2023 at 9:26
  • 1
    I started to write my answer before yours was posted. It took a while longer, because I tested the different font sizes and made a tikz highlight. Otherwise, I probably would have just made a comment to your answer. But yes, the core command here is also hspace.
    – dexteritas
    Jan 19, 2023 at 11:36
3

This may be overkill, but you could use the tikzmark library to add a calligraphic brace to the align* environment, without using cases at all. One advantage is that you don't need to measure anything or approximate negative spacing. This also allows for the easy addition of text to the brace.

Note that you need to add {} to the tikzmarknode for proper spacing.

enter image description here

\documentclass{article}
\usepackage{tikz, amsmath}
\usetikzlibrary{tikzmark, decorations.pathreplacing, calligraphy}
\tikzset{mybrace/.style={decorate, decoration={calligraphic brace, amplitude=1.5mm}, thick}}

\begin{document}

\begin{align*}
a&=b\\
&\tikzmarknode{A}{{}\ge c}\\
&\tikzmarknode{B}{{}\le d}
\end{align*}

\begin{tikzpicture}[overlay, remember picture]
\draw[mybrace] (B.south west)--node[left=1mm]{some text}(A.north west);
\end{tikzpicture}

\end{document}
1
  • I think that that is overkill for this. However, it is very good to know! If I have more complicated things, such as the "some text", then this could be very helpful. So +1!
    – Sam OT
    Jan 19, 2023 at 9:17
1

I have received some excellent answers—and extremely quickly! None are quite as satisfying as I had hoped. Sometimes, there are some seemingly-simple things that LaTeX struggles with, but hey!

Given that there was no simple solution, I include below another version which I had used. As with most of the other answers, it's a bit of a hack. However, it does get the =// signs perfectly aligned; just, the left brace isn't necessarily quite the right size—and \left\{ doesn't work here.

\documentclass{article}
%\usepackage{amsmath}
\usepackage{mathtools}
\begin{document}
\begin{align*}
    a &= b \\
\hspace*{+0.25em}
\mathllap{\Bigg\{}
\hspace*{-0.25em}
&\begin{aligned}
    &\ge c \\
    &\le d
\end{aligned}
\end{align*}
\end{document}

enter image description here

You must log in to answer this question.

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