我使用以下代码在我的 LaTex 文章中插入了一个矩阵:
For a $3 * 3$ grid, given as
\begin{bmatrix}
a & b & c \\
d & e & f \\
g & h & i \\
\end {bmatrix}\\
\vspace{5mm} %5mm vertical space
The determinant is: $ a (ei-hf) - b (di -gf) + c (dh - ge)$
结果是:
我想知道是否有办法将这个矩阵居中?我需要添加什么代码?我正在使用 Atom for Mac。
编辑:这是我的序言:
\documentclass{article}
\usepackage{amsthm}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage[margin=1.25in]{geometry}
\usepackage[shortlabels]{enumitem}
\usepackage{graphicx}
\usepackage{fancyhdr}
\renewcommand{\headrulewidth}{0pt}
\renewcommand{\footrulewidth}{1pt}
\fancyhfoffset{0.2cm}
\pagestyle{fancy}
\rfoot{redacted}
\addtolength{\footskip}{0.2in}
\newtheorem*{theorem}{\sc{Theorem}}
\newtheorem*{definition}{\sc{Definition}}
\newtheorem*{proposition}{\sc{Proposition}}
\newtheorem*{corollary}{\sc{Corollary}}
\newtheorem*{claim}{\sc{Claim}}
\newtheorem*{properties}{\sc{Properties}}
\newtheorem*{remark}{\sc{Remark}}
\DeclareMathOperator{\N}{\mathbb{N}}
\DeclareMathOperator{\Z}{\mathbb{Z}}
\DeclareMathOperator{\Q}{\mathbb{Q}}
\DeclareMathOperator{\R}{\mathbb{R}}
\DeclareMathOperator{\C}{\mathbb{C}
答案1
为了使您的代码片段可编译,并试图集中于与当前问题相关的内容,我提出了以下最小工作示例(MWE):
\documentclass{article}
\usepackage{amsthm,amsmath,amssymb}
\newtheorem*{definition}{\sc{Definition}}
\begin{document}
\begin{definition}
Determinant of a $3 * 3$ grid. For a $3 * 3$ grid, given as
\vspace{5mm} %5mm vertical space
\begin{bmatrix}
a & b & c \\
d & e & f \\
g & h & i \\
\end {bmatrix}\\
\vspace{5mm} %5mm vertical space
The determinant is: $ a (ei-hf) - b (di -gf) + c (dh - ge)$
\end{definition}
\end{document}
此 MWE 在日志文件中生成以下消息记录:
! Missing $ inserted.
<inserted text>
$
l.10 \begin{bmatrix}
?
! Missing $ inserted.
<inserted text>
$
l.15 \end {bmatrix}
\\
?
Underfull \hbox (badness 10000) in paragraph at lines 10--16
一些评论和意见:
! Missing $ inserted.
生成这些消息的原因是bmatrix
必须发生在数学模式中。数学模式中不应有空行。
要将方程(或矩阵)居中而不生成方程编号,请使用
\[
和\]
指令。它们启动和终止显示数学模式,该模式将其内容水平居中。该
\sc
命令不接受参数。此外,它在 LaTeX2e 下已弃用。请将其替换\newtheorem*{definition}{\sc{Definition}}
为\newtheorem*{definition}{\scshape Definition}
。该
Underfull \hbox (badness 10000)
消息是由于\\
行尾存在不必要的指令而生成的\end {bmatrix}\\
。
按照建议的修改后,代码不再发出错误和警告消息。
\documentclass{article}
\usepackage{amsthm,amsmath,amssymb}
\newtheorem*{definition}{\scshape Definition}
\begin{document}
\begin{definition}
Determinant of a $3 * 3$ grid. For a $3 * 3$ grid, given as
\[
\begin{bmatrix}
a & b & c \\
d & e & f \\
g & h & i
\end{bmatrix}
\]
The determinant is: $ a (ei-hf) - b (di -gf) + c (dh - ge)$
\end{definition}
\end{document}
答案2
另一种选择是使用环境center
来使矩阵居中:
\documentclass{article}
\usepackage{amsthm}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage[margin=1.25in]{geometry}
\usepackage[shortlabels]{enumitem}
\usepackage{graphicx}
\usepackage{fancyhdr}
\renewcommand{\headrulewidth}{0pt}
\renewcommand{\footrulewidth}{1pt}
\fancyhfoffset{0.2cm}
\pagestyle{fancy}
\rfoot{redacted}
\addtolength{\footskip}{0.2in}
\newtheorem*{theorem}{\sc{Theorem}}
\newtheorem*{definition}{\sc{Definition}}
\newtheorem*{proposition}{\sc{Proposition}}
\newtheorem*{corollary}{\sc{Corollary}}
\newtheorem*{claim}{\sc{Claim}}
\newtheorem*{properties}{\sc{Properties}}
\newtheorem*{remark}{\sc{Remark}}
\DeclareMathOperator{\N}{\mathbb{N}}
\DeclareMathOperator{\Z}{\mathbb{Z}}
\DeclareMathOperator{\Q}{\mathbb{Q}}
\DeclareMathOperator{\R}{\mathbb{R}}
\DeclareMathOperator{\C}{\mathbb{C}}
\begin{document}
\begin{definition} For a $3 * 3$ grid, given as
\begin{center}%%%%%%%%%%%%%%%%%%%%%% <- start enviroment center
$\begin{bmatrix}
a & b & c \\
d & e & f \\
g & h & i
\end{bmatrix}$
\end{center}
\vspace{5mm} %5mm vertical space
The determinant is: $ a (ei-hf) - b (di -gf) + c (dh - ge)$
\end{definition}
\end{document}