# Missing \$ inserted - trying to center within align

\documentclass{article}
\usepackage{amsmath}
\usepackage{graphicx}
\usepackage{textcomp}
\begin{document}
\begin{align*}
\begin{center}
\theta = ( \pi_0, \beta_0, \beta_1 )\\
f(x_i, z_i, \theta) = 1(z_i = 0) \pi_0 f_0(x_i) + 1(z_i=1)\pi_1 f_1 (x_i)
\end{center}
\end{align*}
\end{document}


I keep getting these kind of errors, and notice it's always when I try to use a \begin inside another \begin. I am VERY new to LaTeX, just got told I have to use it for my final and have no experience.

I feel like I am fundamentally misunderstanding something about TeX.

• Could you edit in the code with your preamble? align and align* should center their equations by default. If you just want multiple equations to be centered, use the gather environment (and you won't need to write \begin{center}...\end{center}). – Arun Debray Dec 12 '15 at 6:09
• Editted it in with another example. – Jibril Dec 12 '15 at 6:18

• If you want each line of a group of equations to be centered, don't use an align or align* environment; instead, use a gather or gather* environment.

• Use the align and align* environments if you need to align the equations on some point, frequently an = symbol or other relational operator.

Depending on the equations' content, it will in general be obvious if gather or align should be used.

• Whatever else you do, do not use a center environment inside a gather or align environment. The center environment is meant for text-mode material only.

A separate issue: you may want to think about using different outputs for 1 depending on whether it's a simple digit or represents the indicator function. The amsmath package provides the instruction \DeclareMathOperator, which is used below to set up a macro called \One. (I know, not very imaginative...) In the example below, \One outputs a bold 1 symbol. You're of course free to choose a different output. For instance, if you wanted a "double-struck" (aka "blackboard bold") look, you could load the dsfont package and declare \DeclareMathOperator{\One}{\mathds{1}}.

\documentclass{article}
\usepackage{amsmath} % for "align" and "gather" environments and "\DeclareMathOperator" macro
\DeclareMathOperator{\One}{\mathbf{1}} % symbol for indicator function
\begin{document}

\begin{gather*}
\theta = ( \pi_0, \beta_0, \beta_1 )\\
f(x_i, z_i, \theta) = \One(z_i = 0) \pi_0 f_0(x_i) + \One(z_i=1)\pi_1 f_1 (x_i)
\end{gather*}

\begin{align*}
\theta &= ( \pi_0, \beta_0, \beta_1 )\\
f(x_i, z_i, \theta) &= \One(z_i = 0) \pi_0 f_0(x_i) + \One(z_i=1)\pi_1 f_1 (x_i)
\end{align*}

\end{document}