我刚刚开始使用 LaTeX,遇到了一点错误。以下是文档:
\documentclass{article}
%preamble%
\usepackage{amsmath}
\title{An Introduction to Functions and their Derivatives}
\author{Purple Bat}
\date{September 4th, 2018}
\begin{document}
\maketitle
\newpage
\section{Functions}
In mathematics, a function is often described as \(f(x)\) or \(g(x)\), where \(x\) is the input value.
For example: \[f(x) = x+2\]
\[g(x) = x\]
By assigning a value to x, we can plug it into the function, and come up with a value. Hence,
\[f(x) = x+2,\ x=3\]
Thus, by plugging the x-value into the function, we get:
\[f(3)=3+2\]
Thus,
\begin{align*}
&=3+2\\
%
&=5
\end{align*}
By plugging in the same x-value for \(g(x)\), we get:
\[g(3)=3\]
There is a third function, \(h(x)\), which can be defined by \[\frac{f(x)}{g(x)}\]
Utilizing the previously defined functions \(f(x)\) and \(g(x)\), we can define \(h(x)\) as:
\begin{align*}
\(h(x)\)=\frac{f(x)}{g(x)}\\
%
&= \frac{x+2}{3}
%
\end{align*}
\end{document}
现在,奇怪的是:第一组对齐的方程式编译没有问题。第二组我遇到了错误。除了添加注释中断(为了便于阅读)外,两个对齐都相同。那么为什么第一个可以编译而第二个不能呢?
答案1
%
正如 Phelype Oleinik 在评论中所说的那样:如果不至少添加一个来注释掉它,方程式中就不能有空行。
我修改了你的代码如下:
\documentclass{article}
%preamble%
\usepackage{amsmath}
\title{An Introduction to Functions and their Derivatives}
\author{Purple Bat}
\date{September 4th, 2018}
\begin{document}
\section{Functions}
In mathematics, a function is often described as \(f(x)\) or \(g(x)\), where \(x\) is the input value.
For example:
\begin{gather*}
f(x) = x+2\\
g(x) = x
\end{gather*}
%
By assigning a value to x, we can plug it into the function, and come up with a value. Hence,
\[f(x) = x+2,\ x=3\]
%
Thus, by plugging the x-value into the function, we get:
\[f(3)=3+2 = 5\]
%
By plugging in the same x-value for \(g(x)\), we get:
\[g(3)=3\]
%
There is a third function, \(h(x)\), which can be defined by \[\frac{f(x)}{g(x)}\]
Utilizing the previously defined functions \(f(x)\) and \(g(x)\), we can define \(h(x)\) as:
%
\begin{align*}
h(x)&=\frac{f(x)}{g(x)}\\
&= \frac{x+2}{x}
\end{align*}
\end{document}
在align*
环境中,您使用一次“列分隔符” &
(在第二个“行”中)。为了让 LaTeX 知道应该对齐什么,您还必须在第一行添加一个。
我想添加其他内容:通过用空行分隔每行文本,您将获得非常丑陋的外观(由于每个新段落的缩进!)这就是我添加的原因%
!