Reputation: 545
I am trying to get equation numbers when knitting my .Rmd to .docx but I haven't found a way to get this or the labels to cross reference them to work. I tried this:
$$
P(L|C_L, C_R) = \frac {10^{\sum_{n=1}^ {4} (w_{c_{L,i}} - w_{c_{R,i}})}} {1+10^{\sum_{n=1}^ {4} (w_{c_{L,i}} - w_{c_{R,i}})}}
$$\label(#eq:left)
The probability for the left side winning can be calculated using \@ref(eq:left)
Which returns this:
Referencing correctly to the equation but the label for it doesn't show (having a (1) on the left or right of the equation) and instead, it prints out the text in the code.
Does anyone know what am I writing wrong here or if this is even possible to do for .docx files?
Thanks for your help
Upvotes: 2
Views: 1852
Reputation: 181
The within-document cross-referencing seems only to work with Bookdown output formats - i.e. word_document2 see here: https://bookdown.org/yihui/rmarkdown-cookbook/cross-ref.html
You could do use the pdf_document output and use the generic LaTeX reference for equations:
\begin{equation} \label{eq:left}
P(L|C_L, C_R) = \frac {10^{\sum_{n=1}^ {4} (w_{c_{L,i}} - w_{c_{R,i}})}}
{1+10^{\sum_{n=1}^ {4} (w_{c_{L,i}} - w_{c_{R,i}})}}
\end{equation}
with the following to put in the reference:
The probability for the left side winning can be calculated using
equation \ref{eq:left}.
The result will look like this (depending on the number of equations and sections):
The probability for the left side winning can be calculated using equation 1
Upvotes: 0
Reputation: 1716
papaja
extends bookdown
, so the general approach you are trying is correct, but the syntax is a little off. Try the following:
\begin{equation}
P(L|C_L, C_R) = \frac {10^{\sum_{n=1}^ {4} (w_{c_{L,i}} - w_{c_{R,i}})}} {1+10^{\sum_{n=1}^ {4} (w_{c_{L,i}} - w_{c_{R,i}})}}
(\#eq:left)
\end{equation}
The probability for the left side winning can be calculated using \@ref(eq:left)
Note that equation references are not well supported in Word (i.e., apa6_docx()
). See the here for details.
Upvotes: 2