-->

How can the backticks (`) printed around these tab

2020-07-25 10:12发布

问题:

In Align multiple tables side by side, a user asks about aligning tables, and the (very good) answer provided involves using latex in a chunk with the results returned as is to LaTeX. This is correct for that users question.

I am curious if this can be easily converted into an inline (i.e. not in chunk) solution.

\begin{table}[!htb]
    \begin{minipage}{.5\linewidth}
      \caption{}
      \centering,
       `r t1`,
    \end{minipage}%
    \begin{minipage}{.5\linewidth}
      \centering
        \caption{},
        `r t2`,
    \end{minipage} 
\end{table}

This is almost successful, however the backticks which are required to call the objects from R, end up also being printed to the output. What have I missed? Is it possible to escape the backticks from LaTeX, but not from the R process?

Update: After requests for reproducibility, please see the full markdown of my solution combined with the other answer I linked and referred to as well as a screencap of the output pdf

回答1:

The backticks are interpreted correctly, as is shown in the following example:

---
title: 'A title'
author: 'An author'
date: 'A date'
output: 
  pdf_document
---

```{r include=FALSE}
myvar1 <- 5 * cos(pi / 3)
myvar2 <- 10 * sin(pi / 6)
```

`myvar1` is `r myvar1`; `myvar2` is `r myvar2`.

\begin{table}[!htb]
    \begin{minipage}{.5\linewidth}
      \caption{}
      \centering
       `r myvar1`
    \end{minipage}%
    \begin{minipage}{.5\linewidth}
      \centering
        \caption{}
        `r myvar2`
    \end{minipage} 
\end{table}

In your example the backticks would also not be printed, but the ,s you left as part of your code will be. You may have been mistaken by the ,s looking like backticks.