1

I'm trying to align piecewise functions, not within the piecewise functions but the actual functions themselves. I use this piece of code but I keep getting a tonne of error messages:

    \begin{align}
    M(x)& = 
    \begin{displaymath}
       \left\{
         \begin{array}{lr}
           2(2x) \hspace{35pt} x < 0.5\\
           2(2 - 2x) \hspace{16pt} x > 0.5
         \end{array}
       \right.
    \end{displaymath} \\
    & =  \begin{displaymath}
       \left\{
         \begin{array}{lr}
           4x \hspace{35pt} x < 0.5\\
           4 - 4x \hspace{16pt} x > 0.5
         \end{array}
       \right.
    \end{displaymath} \\
    \end{align}
3
  • See this section :).
    – Symbol 1
    May 22 '15 at 2:50
  • 2
    Have you tried the cases environment from the amsmath package? Also, you can't use a displaymath environment within an align environment. May 22 '15 at 2:50
  • By the way: Welcome to TeX.SX! You can have a look at our starter guide to familiarize yourself further with our format.
    – Symbol 1
    May 22 '15 at 2:50
7

You could use cases environment for piecewise functions ...

\documentclass{article}
\usepackage{amsmath}

\begin{document}

\begin{align}
    M(x)& = 
    \begin{cases}
       2(2x),&  x < 0.5,\\
       2(2 - 2x),& x > 0.5
    \end{cases} \\
    & =  \begin{cases}
          4x,& x < 0.5,\\
          4 - 4x,& x > 0.5
         \end{cases}
\end{align}

\end{document}

enter image description here

2
  • I wouldn't say "must", there are other alternatives, including variants on the cases theme - but you are right that this is surely the best solution here: +1
    – Au101
    May 22 '15 at 15:15
  • Yeah, your are right
    – juanuni
    May 23 '15 at 2:26

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.