LaTeX公式左对齐、设置Cambria Math字体及调整字号问题
修改后完整代码
% 1. 正文设置为11pt,加载amsmath时加fleqn参数实现全局公式左对齐 \documentclass[11pt,leqno,fleqn]{article} \pagestyle{headings} % 2. 加载unicode-math设置Cambria Math字体,仅支持XeLaTeX/LuaLaTeX编译 \usepackage{amsmath} \usepackage{unicode-math} \setmathfont{Cambria Math} % 设置公式左侧缩进为1em,可按需调整数值 \setlength{\mathindent}{1em} % 3. 重定义pmatrix环境,内部自动使用10pt字号(11pt正文下\small对应10pt) \let\oldpmatrix\pmatrix \def\pmatrix{\small\oldpmatrix} %\usepackage[left=2.2cm, top=2cm, right=1.32cm, bottom=1.59cm]{geometry} \usepackage{titlesec} \usepackage{xcolor} \titleformat{\section}[block]{\Large\bfseries\filcenter}{}{1em}{} \setcounter{secnumdepth}{0} \begin{document} \date{\vspace{-10ex}} 1º) Fazemos uma forward propagation: % 用align环境排版公式对,&标记两个公式的分隔位置,避免手动加空格 \begin{align*} T^{^{\left[1\right]}}=W^{^{\left[1\right]}}\cdot X^{^{\left[0\right]}}+b^{^{\:\left[1\right]}}=\begin{bmatrix}6\\ 1\\ 6\end{bmatrix} && X^{^{\left[1\right]}}=\tanh\left(\begin{bmatrix}6\\ 1\\ 6\end{bmatrix}\right)=\begin{bmatrix}0.9999877\\ 0.761594\\ 0.9999877\end{bmatrix} \\[1em] T^{^{\left[2\right]}}=W^{^{\left[2\right]}}\cdot X^{^{\left[1\right]}}+b^{^{\:\left[2\right]}}=\begin{bmatrix}3.7615694\\ 3.7615694\end{bmatrix} && X^{^{\left[2\right]}}=\tanh\left(\begin{bmatrix}3.7615694\\ 3.7615694\end{bmatrix}\right)=\begin{bmatrix}0.99891972\\ 0.99891972\end{bmatrix} \\[1em] T^{^{\left[3\right]}}=W^{^{\left[3\right]}}\cdot X^{^{\left[2\right]}}+b^{^{\:\left[3\right]}}=\begin{bmatrix}0\\ 0\end{bmatrix} && X^{^{\left[3\right]}}=\tanh\left(\begin{bmatrix}0 \\ 0\end{bmatrix}\right)=\begin{bmatrix}0 \\ 0\end{bmatrix} \end{align*} \end{document}
关键调整说明
- 正文字号:将documentclass的参数从13pt改为11pt,实现全局正文字号11pt的要求。
- 公式左对齐:加载amsmath时添加
fleqn参数,实现所有行间公式默认左对齐,可通过\setlength{\mathindent}{数值}调整公式左侧的缩进距离。同时替换原生的$$语法为amsmath提供的align*环境排版多公式对,避免手动添加大量空格调整位置。 - Cambria Math字体:引入
unicode-math包,通过\setmathfont{Cambria Math}指定全局数学字体,该配置仅支持XeLaTeX、LuaLaTeX编译器。 - 矩阵字号10pt:重定义
pmatrix环境,调用时自动切换到\small字号,11pt正文基准下\small对应字号刚好为10pt,无需手动为每个矩阵添加字号命令。
内容的提问来源于stack exchange,提问作者Martim Correia
相关产品推荐
相关产品推荐

