gpt4 book ai didi

rmarkdown 矩阵未按预期运行或在 rstudio 中看到

转载 作者:行者123 更新时间:2023-12-04 12:00:27 26 4
gpt4 key购买 nike

我正在尝试使用 Rmarkdown 创建一个 blogdown 帖子,但我正在尝试创建的矩阵没有给出正确的输出。在 Rstudio 中,它看起来像下图,但是当我运行 rmarkdown 时,我得到了不同的结果。

enter image description here

在 blogdown 中给出输出:

enter image description here

Markdown 代码:

$$
\left(\begin{array}{cccc}
\text{var } & ... & -1 \\
\text{cov } & ... & ...\\
\text{mat } & ... & -1 \\
... & ... & -1\\
1 & ... & 0
\end{array}\right)

\left(\begin{array}{c}
w_{1} \\
... \\
... \\
... \\
w_{k} \\
\lambda
\end{array}\right)

=

\left(\begin{array}{c}
0 \\
... \\
... \\
... \\
0 \\
1
\end{array}\right)
$$

关于我哪里出错以及如何使矩阵方程与 RStudio 输出在同一行上有什么想法吗?

最佳答案

空行破坏了东西。来自 https://tex.stackexchange.com/q/230338

An empty line in TeX should never be used just to arrange the source. It is an instruction exactly the same as the command \par which ends a paragraph and starts TeX's line breaking algorithm to split a paragraph into lines.

So it is not allowed in display math and it should never be used on the line before display math either, in that position it does not generate an error but forces TeX to take recovery action that produces a spurious white paragraph on the line above the display.

  • David Carlisle, Feb 26 '15 at 21:29

虽然 LaTeX 限制将自身强加于 HTML 目标似乎并不明显,但渲染使用 MathJax(javascript 库)渲染 LaTeX 数学模式。

如果您删除它们,它似乎可以正确呈现。

---
title: Quux
output: html_document
---

$$
\left(\begin{array}{cccc}
\text{var } & ... & -1 \\
\text{cov } & ... & ...\\
\text{mat } & ... & -1 \\
... & ... & -1\\
1 & ... & 0
\end{array}\right)
\left(\begin{array}{c}
w_{1} \\
... \\
... \\
... \\
w_{k} \\
\lambda
\end{array}\right)
=
\left(\begin{array}{c}
0 \\
... \\
... \\
... \\
0 \\
1
\end{array}\right)
$$

rmarkdown rendering into HTML

它也适用于输出:pdf_document:

rmarkdown rendering into PDF

R.version
# _
# platform x86_64-w64-mingw32
# arch x86_64
# os mingw32
# system x86_64, mingw32
# status
# major 3
# minor 5.3
# year 2019
# month 03
# day 11
# svn rev 76217
# language R
# version.string R version 3.5.3 (2019-03-11)
# nickname Great Truth

packageVersion("knitr")
# [1] '1.23'
packageVersion("rmarkdown")
# [1] '1.13'

关于rmarkdown 矩阵未按预期运行或在 rstudio 中看到,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58943528/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com