插入数学公式

Apr 1, 2019

分类

LaTeX中数学公式的呈现可分为两类:行内公式行间公式

  • 行内公式: 又被称为内联公式(text),即在声明文本的正文之内,也就是说是嵌入文字之间的,与文字在同一行。

  • 行间公式: 又被称为外联公式(displayed),即与正文分开的公式,公式单独占据一行。


实现

这两种公式均有三种方式来实现。

  • 行内公式

    1. 使用$...$方式将公式包含在其中。
    2. 使用\(...\)将公式包含在其中。
    3. 使用\begin {math}\end {math}将公式包含在其中。
  • 行间公式

    1. 使用$$...$$方式将公式包含在其中。
    2. 使用\[...\]将公式包含在其中。
    3. 使用\begin {digplaymath}\end {displaymath}将公式包含在其中。

下例中以不同的方式进行了x + y = 10这个公式的实现:

%!TEX program = xelatex

\documentclass{article}
    \begin{document}
        test test test $x + y = 10$ test test test

        test test test \(x + y = 10\) test test test

        test test test
        \begin{math}
            x + y = 10
        \end{math}
        test test test


        test test test $$x + y = 10$$ test test test

        test test test \[x + y = 10\] test test test

        test test test
        \begin{displaymath}
            x + y = 10
        \end{displaymath}
        test test test

    \end{document}

结果如下:
不同方式插入数学公式


注:

LaTeX中会将换行符忽略,若要实现在文档中换行,需在要换行处添加空行。这样在实现的文档中会另起一段,且若是默认情况下,在每一段开始,LaTeX在处理时会自动添加4个字符的缩进。这里仅讨论关于在文档中添加数学公式的方法,对于换行等格式的控制暂不展开说明。