Text FormattingThe & operator in piecewise functions

Information and discussion about LaTeX's general text formatting features (e.g. bold, italic, enumerations, ...)
Post Reply
sobrio35
Posts: 3
Joined: Sun May 25, 2014 7:53 pm

The & operator in piecewise functions

Post by sobrio35 »

This code is producing the error message "Misplaced alignment tab character &". I've tried everything I can think of and no topics cover this that I can find. Ideas?

Code: Select all

\[
f(x) = 
\begin{cases}
1 & if 0 \leq x < \pi \\
0 & if \pi \leq x < 2 \pi
\end{cases}
\]
For now I really don't care about anything but compiling. The rest I can sort out later. Is there something easy I'm missing?

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

Johannes_B
Site Moderator
Posts: 4182
Joined: Thu Nov 01, 2012 4:08 pm

The & operator in piecewise functions

Post by Johannes_B »

Please always try to prepare a minimal working example. Simply adding a documentclass to your example shows, that there is nothing wrong with the code.

Code: Select all

\documentclass{article}
\usepackage{mathtools}
\begin{document}
\[
	f(x) =
	\begin{cases}
		1 & if 0 \leq x < \pi \\
		0 & \text{if } \pi \leq x < 2 \pi%please note the
%		extra text command 
	\end{cases}
\]
\end{document}
Please click on »open in writelatex« just above the code to test.
The smart way: Calm down and take a deep breath, read posts and provided links attentively, try to understand and ask if necessary.
User avatar
Stefan Kottwitz
Site Admin
Posts: 10347
Joined: Mon Mar 10, 2008 9:44 pm

The & operator in piecewise functions

Post by Stefan Kottwitz »

I guess you forgot to load amsmath:

\usepackage{amsmath}

Johannes loaded mathtools, which automatically loads amsmath. That's why his example works fine. The older (non-amsmath) syntax of cases is different, that's why you would get this error.

Stefan
LaTeX.org admin
User avatar
Johannes_B
Site Moderator
Posts: 4182
Joined: Thu Nov 01, 2012 4:08 pm

The & operator in piecewise functions

Post by Johannes_B »

When math is present, i always use mathtools. As Stefan already mentioned, it loads amsmath and also provides some fixes. If you need math, please read the docs of amsmath and mathtools. You will find some interessting things there.

Thanks @Stefan for pointing that out.
The smart way: Calm down and take a deep breath, read posts and provided links attentively, try to understand and ask if necessary.
Post Reply