LaTeX How can I write a piecewise function in LaTeX?

AI Thread Summary
To write a piecewise function in LaTeX, ensure to use "\left\{" instead of "\left{" and add a period after "\right" for proper rendering. The corrected code should look like this: f(x)=\left\{ \begin{array}{ll} 1 & x \in \mathbb{Q} \\ 0 & x \notin \mathbb{Q} \end{array} \right.. Alternatively, using the "\begin{cases}" environment can also achieve the desired output: f(x)=\begin{cases}1 & x\in\mathbb{Q}\\ 0 & x\notin\mathbb{Q} \\ \end{cases}. These adjustments will ensure the piecewise function displays correctly in LaTeX. Proper syntax is essential for accurate mathematical representation.
TheBigBadBen
Messages
79
Reaction score
0
I was trying to type a piecewise function, and then this happened:

$$
f(x)=\left{ \begin{array}{ccc}
1 & x \in \mathbb{Q} \\
0 & x \notin \mathbb{Q}
\end{array} \right
$$

What's going on, and how do I fix it?
 
Physics news on Phys.org
Hi TheBigBadBen, :)

There are two small things to fix and it works just fine. The first is when you want to add brackets {} using Mathjax you need to add another slash before it. So it should read "\left \{". The other thing is at the end of "\right" you need to add a period. If you do those two things this is what renders.

$$
f(x)=\left\{ \begin{array}{ll}
1 & x \in \mathbb{Q} \\
0 & x \notin \mathbb{Q}
\end{array} \right.$$
 
Another approach:

Try the code:

Code:
f(x)=\begin{cases}1 & x\in\mathbb{Q}\\ 0 & x\notin\mathbb{Q} \\ \end{cases}

to get:

$$f(x)=\begin{cases}1 & x\in\mathbb{Q}\\ 0 & x\notin\mathbb{Q} \\ \end{cases}$$
 

Similar threads

Replies
4
Views
3K
Replies
6
Views
2K
Replies
2
Views
5K
Replies
3
Views
2K
Replies
7
Views
3K
Replies
4
Views
4K
Replies
1
Views
2K
Replies
5
Views
2K
Replies
1
Views
2K
Replies
3
Views
3K
Back
Top