How can the backticks (`) printed around these tables be escaped?

不打扰是莪最后的温柔 提交于 2019-12-22 18:35:02

问题


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.



来源:https://stackoverflow.com/questions/48211887/how-can-the-backticks-printed-around-these-tables-be-escaped

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!