Dasr
Dasr

Reputation: 828

Multiline cross-referenced equation in rmarkdown - knit to pdf

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.

Upvotes: 3

Views: 689

Answers (1)

Aaron Montgomery
Aaron Montgomery

Reputation: 1387

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.

Upvotes: 3

Related Questions