# [Tex/LaTex] How to number a conditional equation

conditionalsequations

I am writing the following syntax to get a conditional equation. But the equation is not numbered. How can I number it?

$f(x) = \begin{cases} x+7 & \text{if 5< x}; \\ x^2-3 & \text{if -3 \le x \le 5};\\ -x & \text{if x < -3}. \end{cases}$


Instead of using$...$, you can use the align command. The MWE (minimum working example) is presented below:

\documentclass{article}
\usepackage{amsmath}

\begin{document}
\begin{align}
f(x) = \begin{cases}
x+7 & \text{if $5< x$}; \\
x^2-3 & \text{if $-3 \le x \le 5$};\\
-x & \text{if $x < -3$}.
\end{cases}
\end{align}
\end{document}


Update

\documentclass{article}
\usepackage{amsmath}
\usepackage{mathtools}
\usepackage{hyperref}

%\usepackage{lipsum} %for example text only

\begin{document}
long long ago, there was a war between the birds and the beasts, no one knows what they fought about.
\begin{align}\SwapAboveDisplaySkip
\label{eq:mycase1}
f(x) = \begin{cases}
x+7 & \text{if $5< x$}; \\
x^2-3 & \text{if $-3 \le x \le 5$};\\
-x & \text{if $x < -3$}.
\end{cases}
\end{align}

\begin{itemize}
\item ref-ing the equation need label equation firstly, just put \verb|\label{key}| after \verb|\begin{align}| or before \verb|\end{align}|, where "key" is a user-defined label and must not be the same for different equations. you can use the label command to label anything else such as "chapter, section, theorem" and so on.

\item referencing equation by command \verb|\ref{key}| or \verb|\eqref{key}|, you can see the ref-ed function number here as \ref{eq:mycase1} or \eqref{eq:mycase1}.

\item you can changing the numbered equation format using \verb|\tag|.
\begin{align}\SwapAboveDisplaySkip
\label{eq:mycase2}
\tag{*}
f(x) = \begin{cases}
x+7 & \text{if $5< x$}; \\
x^2-3 & \text{if $-3 \le x \le 5$};\\
-x & \text{if $x < -3$}.
\end{cases}
\end{align}
there is a tagged ref \eqref{eq:mycase2}.

\item you should try to use package hyperref for a linked ref or autoref. linked ref is \eqref{eq:mycase1}, you can use autoref command which gives  \autoref{eq:mycase1}. changing the autoref name with the command \verb|\def\equationautorefname{funautoref}| which always be put in preamble.
\def\equationautorefname{funautoref}
so there is changed name \autoref{eq:mycase1}.

\item some packages provide a convenient way, such as cleveref and nameref.

\item at last, maybe you need define a theorem environment or some other environments for your article.

\item a big skip will be made when using align, the problem can be fixed with setting
\begin{verbatim}
\setlength{\belowdisplayskip}{2pt}
\setlength{\abovedisplayskip}{2pt}
\setlength{\belowdisplayshortskip}{2pt}
\setlength{\abovedisplayshortskip}{2pt}
\end{verbatim}
with suitable value "after" \verb|\begin{document}|. but mathtools package maybe is a good choice, it fixs the space with \verb|\SwapAboveDisplaySkip| command. \\
befor
\begin{align}
\label{eq:mycase2}
f(x) = \begin{cases}
x+7 & \text{if $5< x$}; \\
x^2-3 & \text{if $-3 \le x \le 5$};\\
-x & \text{if $x < -3$}.
\end{cases}
\end{align}
after
\begin{align}\SwapAboveDisplaySkip
\label{eq:mycase2}
f(x) = \begin{cases}
x+7 & \text{if $5< x$}; \\
x^2-3 & \text{if $-3 \le x \le 5$};\\
-x & \text{if $x < -3$}.
\end{cases}
\end{align}
\end{itemize}

The bat did not know whose side he should take. He thought and thought, then decided he must try to be on the side of the winners.

So he watched from far away. After a while, it seemed that the birds were going to win.He flew over to join them.
\end{document}