如何对条件方程进行编号

如何对条件方程进行编号

我正在编写以下语法来获取条件方程。但方程没有编号。我该如何给它编号?

\[ 
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}
\]

答案1

除了使用\[...\],您还可以使用align命令。MWE(最小工作示例)如下所示:

\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}

更新

\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}

答案2

更新

\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}

相关内容