Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiline cross-referenced equation in rmarkdown - knit to pdf

Tags:

r

r-markdown

I'm trying to create rmarkdown pdf document and introduce a multiline equation in it. Here is the header:

title: "Cross-referencing figures, tables, and equations"
author: "Generated by bookdown"
output:
  pdf_document: default
  bookdown::pdf_document2: default
  bookdown::html_document2: default

I need to be able to cross-reference the equation and for it to be split among multiple lines as it's long. I've tried multiple different things by looking at other posts, with the latest being the following:

\begin{align} 
g(X_{n}) &= g(\theta)+g'({\tilde{\theta}})(X_{n}-\theta) \notag \\
\sqrt{n}[g(X_{n})-g(\theta)] &= g'\left({\tilde{\theta}}\right)
  \sqrt{n}[X_{n}-\theta ] (\#eq:align)
\end{align}

The above works fine apart that I can't cross-reference using @ref(eq:align, and (\#eq:align) randomly appears in the equation. Could someone advise as to how I can get this to work?

Thank you.

like image 338
Dasr Avatar asked Jan 25 '26 10:01

Dasr


1 Answers

Does the following help?

\begin{align} 
g(X_{n}) &= g(\theta)+g'({\tilde{\theta}})(X_{n}-\theta) \notag \\
\sqrt{n}[g(X_{n})-g(\theta)] &= g'\left({\tilde{\theta}}\right)
  \sqrt{n}[X_{n}-\theta ] \label{eq:align}
\end{align}

As we see from \eqref{eq:align}, Pythagoras was right all along!

The idea is to just use the LaTeX method of assigning labels and referencing with \label and \eqref.

like image 100
Aaron Montgomery Avatar answered Jan 26 '26 22:01

Aaron Montgomery