5

I was trying to achieve an alignment inside a cases environment. Here is what I was trying to achieve:

enter image description here

I actually was able to achieve the above using the following MathJax code:

$$
f(x,y) = 
\begin{cases} 
\begin{align*}
x&=1, & y&=1 \\
x&=10, & y&=20
\end{align*}
\end{cases}
$$

I realize that $$ is not proper LaTeX syntax, but I'm not sure what to substitute it with.

Now, when I try to put this inside a LaTeX document, it gives me a few errors and doesn't line everything up properly into two columns (there is only one column).

\documentclass{article}
\usepackage{amsmath}

\begin{document}

$$
f(x,y) = 
\begin{cases} 
\begin{align*}
x&=1, & y&=1 \\
x&=10, & y&=20
\end{align*}
\end{cases}
$$

\end{document}

Here is something else I tried, which reduced the graphical errors, but still puts it inside only one column:

\documentclass{article}
\usepackage{amsmath}

\begin{document}

\begin{align*}
f(x,y) = 
\begin{cases} 
u &= \ln x & v' &= 1 \\
u' &= \frac{1}{x} & v &= x \\
\end{cases}
\end{align*}

\end{document}

I would also like to control the spacing with the alignat environment, but I need to find out how to do this first before I can start thinking about that :)

  • 2
    texdoc amsmath ? align is a display environment (you can use aligned for subterms. – David Carlisle Sep 24 '17 at 16:10
  • 1
    the latex equivalent to $$..$$ (which is also the mathjax default) is \[..\] – David Carlisle Sep 24 '17 at 16:12
  • Don't use$$ ... $$. See the answer to this question. – Bernard Sep 24 '17 at 16:15
  • 2
    MathJax is not LaTeX; it (wrongly) allows constructions that are illegal as LaTeX code and this is an example. – egreg Sep 24 '17 at 16:29
2

The simplest is to use empheq + alignat*. Needless to load amsmath, since empheq loads mathtools, which does it for you.

\documentclass{article}%
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{empheq}

\begin{document}

\begin{empheq}[left={f(x, y)=\empheqlbrace}]{alignat*=2}
    x &=1, &\quad y &=1 \\
    x &=10, & y &=20
\end{empheq}

\end{document} 

enter image description here

4

enter image description here

align is for complete display math, aligned is the version for subterms.

\documentclass{article}
\usepackage{amsmath}

\begin{document}

\[
f(x,y) = 
\left\{
\begin{aligned}
x&=1, & y&=1 \\
x&=10, & y&=20
\end{aligned}
\right.
\]

\end{document}

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.