我正在 rmarkdown 中将针织转换为 pdf。我已将方程式(以及其他所有内容?)设置为默认左对齐,方法是
classoption: fleqn
在我的 rmarkdown 文件顶部的 YAML 元数据中。
我想知道如何指定某些方程式居中对齐,同时仍保持文本和方程式默认的左对齐。我搜索过这个论坛并运行了许多示例,但代码似乎在 rmarkdown 中不起作用。
这是一个示例 rmarkdown 文档。
---
title: "centering equations"
output:
pdf_document: default
html_document: null
word_document: null
toc: yes
linestretch: 1.3
classoption: fleqn
header-includes:
- \setlength{\mathindent}{0pt}
- \setlength\parindent{0pt}
---
This is some text
This is the equation I would have centered.
\begingroup\large
\begin{align*}
h(t_{ij}) = Pr[T_{i}=j|T_{i}\geq j].
\end{align*}
\endgroup
答案1
将方程设在跨越整个的框内\linewidth
:
---
title: "centering equations"
output:
pdf_document: default
classoption: fleqn
header-includes:
- \setlength{\mathindent}{0pt}
- \setlength{\parindent}{0pt}
---
This is some text
This is the equation I would like left aligned:
\[
h(t_{ij}) = Pr[ T_i = j| T_i \geq j |
\]
This is the equation I would like centred:
\[
\makebox[\linewidth]{$h(t_{ij}) = Pr[ T_i = j| T_i \geq j |$}
\]
\noindent
\makebox[\linewidth]{centered text}
This is a set of equations to align centred:
\[
\makebox[\linewidth]{$\displaystyle
\begin{aligned}
f(x) &= ax^2 + bx + c \\
ax^2 + bx + c &= g(x)
\end{aligned}
$}
\]