PPTX

公式与符号

向幻灯片添加数学公式和特殊符号

你可以在演示文稿中包含数学公式和特殊符号。

文本片段中的公式

使用 Unicode 字符和特殊格式来表示公式:

import { Shape, Paragraph, TextRun } from "@office-open/pptx";

new Shape({
    x: 1,
    y: 1,
    width: 8,
    height: 3,
    paragraphs: [
        new Paragraph({
            children: [
                new TextRun({ text: "E = mc", fontSize: 28 }),
                new TextRun({ text: "²", fontSize: 20, superScript: true }),
            ],
        }),
        new Paragraph({
            children: [
                new TextRun({ text: "H", fontSize: 28 }),
                new TextRun({ text: "2", fontSize: 20, subScript: true }),
                new TextRun({ text: "O", fontSize: 28 }),
            ],
        }),
    ],
});

上标和下标

new TextRun({ text: "x", fontSize: 24 });
new TextRun({ text: "2", fontSize: 16, superScript: true }); // x²
new TextRun({ text: "n", fontSize: 16, subScript: true }); // 下标

常用数学符号(Unicode)

new TextRun({ text: "π", fontSize: 24 }); // 圆周率
new TextRun({ text: "Σ", fontSize: 24 }); // 求和符号
new TextRun({ text: "", fontSize: 24 }); // 积分
new TextRun({ text: "", fontSize: 24 }); // 平方根
new TextRun({ text: "±", fontSize: 24 }); // 正负号
new TextRun({ text: "", fontSize: 24 }); // 不等于
new TextRun({ text: "", fontSize: 24 }); // 小于等于
new TextRun({ text: "", fontSize: 24 }); // 大于等于
new TextRun({ text: "", fontSize: 24 }); // 右箭头
new TextRun({ text: "×", fontSize: 24 }); // 乘号
new TextRun({ text: "÷", fontSize: 24 }); // 除号
new TextRun({ text: "", fontSize: 24 }); // 无穷大

复杂公式布局

使用多个段落构建多行公式:

new Shape({
    x: 1,
    y: 1,
    width: 8,
    height: 4,
    paragraphs: [
        new Paragraph({
            alignment: "center",
            children: [new TextRun({ text: "Quadratic Formula", fontSize: 18, bold: true })],
        }),
        new Paragraph({
            alignment: "center",
            children: [
                new TextRun({ text: "x = (-b ± √(b", fontSize: 24 }),
                new TextRun({ text: "2", fontSize: 16, superScript: true }),
                new TextRun({ text: " - 4ac)) / 2a", fontSize: 24 }),
            ],
        }),
    ],
});

提示

  • 使用 superScript: true 表示指数,subScript: true 表示下标。
  • Unicode 数学符号在大多数演示文稿查看器中都能正确渲染。
  • 对于复杂的数学表达式,建议使用从 LaTeX 渲染的公式图片。
Copyright © 2026