# Formatting piecewise function

I need to write this

So far I started my code this way:

\documentclass{article}
\usepackage{amsmath}
\usepackage{amssymb}

\begin{document}
\begin{equation*}
\begin{cases}
u_t+2uu_x=0,              & x \in \mathbb{R}, t>0\\
u(x,0)=g(x)=\begin{cases}
-1/2, & x<0,\\
1/2, & x>0.
\end{cases}
\end{cases}
\end{equation*}
\end{document}


I get a similar result, which is not really in the same format. The equation are not aligned according to the equal sign, and I have an extra open parenthesis which I don't know how to remove.

• Seems you want align* instead of an equation environment. Put & before the equal signs. Sep 17 '17 at 11:13

\documentclass{article}
\usepackage{amsmath}
\usepackage{amssymb}

\begin{document}
\begin{align*}
u_t+2uu_x   & = 0 ,\quad          x \in \mathbb{R}, t>0\\
u(x,0) = g(x) & = \begin{cases}
-1/2, & x<0,\\
1/2, & x>0.
\end{cases}
\end{align*}
\end{document}


or maybe (stole from Werner's answer):

\documentclass{article}
\usepackage{mathtools, amssymb}

\makeatletter
\hfil$\m@th\displaystyle{##}$}{$\m@th\displaystyle{##}$\hfil}{\lbrace}{.}
\makeatother

\begin{document}
\begin{align*}
u_t+2uu_x   & = 0 ,\quad          x \in \mathbb{R}, t>0\\
u(x,0) = g(x) & = \begin{mycases}
-1/2, & x<0,\\
1/2, & x>0.
\end{mycases}
\end{align*}
\end{document}


• Very nice! I am not sure I understand the \quad though Sep 17 '17 at 13:47
• \quad determine space between variables or words in math environments (equations). I suggest you to read some introductory literature about latex, for example tobi.oetiker.ch/lshort/lshort.pdf and more advanced about math in latex researchgate.net/publication/… Sep 17 '17 at 14:05
• I would align left, by moving the & at the beginning of the lines. Sep 17 '17 at 15:28
• i only follow to op wish :-) , however i agree with you. Sep 17 '17 at 18:52