这是我的代码:
\begin{center}
\begin{tabular}{ |c|c| }
\hline
\int dx = x + C & \int \frac{dx}{\cos ^{x}} = tg x + C \\
\int x^{a} dx = \frac{x ^{a + 1}}{a + 1} + C (a \neq -1) & \int \frac{dx}{\sin ^{2}x} = - ctg x \\
\hline
\end{tabular}
\end{center}
它按我想要的方式显示,但是这个错误不断弹出:
Missing } inserted. \int dx = x + C &
答案1
因此问题在于,tabular
您始终处于文本模式,因此您需要使用例如切换到数学模式$ .. $
。
也可以按列进行操作,因此您不需要在每个单元格中都输入美元符号。请参见下面的第二个示例。这需要\usepackage{array}
。
如果您使用array
而不是tabular
内部数学模式,则每个单元格也处于数学模式。请参阅下面的第三个示例。
但在这种情况下,仅使用构造可能看起来更好align*
,请参见下面的最后一个例子。
\documentclass{article}
\usepackage{amsmath,array}
\DeclareMathOperator{\ctg}{ctg}
\newcommand{\diff}{\mathop{}\!d} % thanks egreg
\begin{document}
Math mode in each cell:
\begin{center}
\begin{tabular}{ |c|c| }
\hline
$\int \diff x = x + C$ & $\int \frac{\diff x}{\cos ^{2}x} = \tan x + C $\\
$\int x^{a} \diff x = \frac{x ^{a + 1}}{a + 1} + C (a \neq -1)$ & $\int \frac{\diff x}{\sin ^{2}x} = - \ctg x $\\
\hline
\end{tabular}
\end{center}
Two columns all math mode:
\begin{center}
\begin{tabular}{ |*{2}{ >{$} c <{$} | } }
\hline
\int \diff x = x + C & \int \frac{\diff x}{\cos ^{2}x} = \tan x + C \\
\int x^{a} \diff x = \frac{x ^{a + 1}}{a + 1} + C (a \neq -1) & \int \frac{\diff x}{\sin ^{2}x} = - \ctg x \\
\hline
\end{tabular}
\end{center}
\texttt{array} inside \texttt{equation*}:
\begin{equation*}
\begin{array}{ |c|c| }
\hline
\int \diff x = x + C & \int \frac{\diff x}{\cos ^{2}x} = \tan x + C \\
\int x^{a} \diff x = \frac{x ^{a + 1}}{a + 1} + C (a \neq -1) & \int \frac{\diff x}{\sin ^{2}x} = - \ctg x \\
\hline
\end{array}
\end{equation*}
\texttt{align*}:
\begin{align*}
\int \diff x &= x + C & \int \frac{\diff x}{\cos ^{2}x} &= \tan x + C \\
\int x^{a} \diff x &= \frac{x ^{a + 1}}{a + 1} + C (a \neq -1) & \int \frac{\diff x}{\sin ^{2}x} &= - \ctg x \\
\end{align*}
\end{document}
答案2
您需要在数学模式中设置数学内容。但是,使用\[
...\]
外部不会tabular
起作用,因为tabular
默认情况下会将其内容设置为文本模式。因此,要么坚持tabular
在每个单元格(或每列)中插入数学模式,并借助array
),或者将\[
...\]
与常规array
:一起使用
\documentclass{article}
\usepackage{amsmath,array,lipsum}
\newcommand{\dx}{\mathrm{d}x}
\DeclareMathOperator{\ctg}{ctg}
\begin{document}
\lipsum[1]
\begin{center}
\renewcommand{\arraystretch}{2}%
\begin{tabular}{ | >{$\displaystyle}c<{$} | >{$\displaystyle}c<{$} | }
\hline
\int \dx = x + C & \int \frac{\dx}{\cos x} = \ctg x + C \\
\int x^{a} \dx = \frac{x ^{a + 1}}{a + 1} + C,\ (a \neq -1) & \int \frac{\dx}{\sin ^{2}x} = - \ctg x \\[.5\normalbaselineskip]
\hline
\end{tabular}
\end{center}
\lipsum[2]
\[
\renewcommand{\arraystretch}{2}
\begin{array}{ | >{\displaystyle}c | >{\displaystyle}c | }
\hline
\int \dx = x + C & \int \frac{\dx}{\cos x} = \ctg x + C \\
\int x^{a} \dx = \frac{x ^{a + 1}}{a + 1} + C,\ (a \neq -1) & \int \frac{\dx}{\sin ^{2}x} = - \ctg x \\[.5\normalbaselineskip]
\hline
\end{array}
\]
\lipsum[3]
\end{document}