【问题标题】:Officedown: equation numbering and cross-referencing not workingOfficedown:公式编号和交叉引用不起作用
【发布时间】:2023-02-01 21:55:39
【问题描述】:

我正在尝试使用 Rmarkdown 在 docx 中生成方程式编号和交叉引用,但它不起作用。

这是我的 YAML

output:
  officedown::rdocx_document:
    reference_docx: ref_transfer.docx
header-includes:
- \usepackage{amsmath}

我试过在用 $$ 括起来的等式块中使用 (\#eq:test)(下面的代码)

\begin{equation} 
\begin{gather}
\text{Y}_{ij} = \alpha_{0} + \beta_{0}\text{X}_{1ij} + \alpha_{1}\text{Z}_{1j} + 
\alpha_{2}\text{Z}_{2j} + \beta_{1}\text{Z}_{1j}\text{X}_{1ij} +
\beta_{2}\text{Z}_{2j}\text{X}_{1ij} + v_j\text{X}_{1ij}  + u_j + \epsilon_{ij} \\
\text{where} \\
\epsilon_{} \sim N(0, \sigma^2) \\
u_j \sim N(0, \sigma^2_u) \\
v_j \sim N(0, \sigma^2_v) 
\end{gather}
(\#eq:test)
\end{equation}

\@ref(eq:test)在线交叉引用。那产生了@ref(当量:测试)在线和(#eq:测试)作为方程式编号,请参见下面的RenderOutput

我也尝试过使用\label{eq:test}(下面的代码)

\begin{equation} 
\begin{gather}
\text{Y}_{ij} = \alpha_{0} + \beta_{0}\text{X}_{1ij} + \alpha_{1}\text{Z}_{1j} + 
\alpha_{2}\text{Z}_{2j} + \beta_{1}\text{Z}_{1j}\text{X}_{1ij} +
\beta_{2}\text{Z}_{2j}\text{X}_{1ij} + v_j\text{X}_{1ij}  + u_j + \epsilon_{ij} \\
\text{where} \\
\epsilon_{} \sim N(0, \sigma^2) \\
u_j \sim N(0, \sigma^2_u) \\
v_j \sim N(0, \sigma^2_v) 
\end{gather}
\label{eq:test}
\end{equation}

\eqref{eq:test} 一起使用。

这会在您希望看到方程式编号和引用的地方产生空白,请参阅RenderOutput2

有没有人可以解决此类问题?请帮忙。

【问题讨论】:

    标签: latex r-markdown pandoc equation officedown


    【解决方案1】:

    要在 word 文档中获得预期的输出,您需要使用 bookdown 进行正确的编号和交叉引用。请参阅下面的 yaml 部分中指定 base_format 参数的位置。

    ---
    output: 
      officedown::rdocx_document:
        base_format: "bookdown::word_document2"
    ---
    
    
    egin{equation}
      egin{gather}
        	ext{Y}_{ij} = lpha_{0} + eta_{0}	ext{X}_{1ij} + lpha_{1}	ext{Z}_{1j} + 
        lpha_{2}	ext{Z}_{2j} + eta_{1}	ext{Z}_{1j}	ext{X}_{1ij} +
        eta_{2}	ext{Z}_{2j}	ext{X}_{1ij} + v_j	ext{X}_{1ij}  + u_j + epsilon_{ij} \
        	ext{where} \
        epsilon_{} sim N(0, sigma^2) \
        u_j sim N(0, sigma^2_u) \
        v_j sim N(0, sigma^2_v) 
      end{gather}
    (#eq:test)  
    end{equation}
    
    This is a cross-reference @ref(eq:test)
    

    我得到的结果是:

    【讨论】:

      猜你喜欢
      • 2020-10-06
      • 1970-01-01
      • 2018-10-14
      • 2021-10-05
      • 2019-08-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-04-25
      相关资源
      最近更新 更多