1

我试图在我的 Tufte Latex 文档中添加一个边注,该文档部分由 r 代码生成,但没有成功。设置为打印在页边距的代码块似乎只在其中放置图表,而不是文本或表格。如果其中包含内联代码,则调用的边距注释tufte::marginfigure()会引发错误。边距图块忽略内联代码。我已经成功地让我的代码生成的文本打印在带有脚注的页边空白处,但是我得到了脚注编号,这是我不想要的。我想关闭那个脚注上的编号,但一直没能。

这是一个例子:

---
title: "Tufte Test"
author: "Neal"
date: "`r Sys.Date()`"
output:
  tufte::tufte_handout: default
---

```{r setup, include=FALSE}
library(tufte)
library(tidyverse)
```

Here is some normal text with inline code: 2+3=`r 2+3`  

\vspace{10pt}
```{r block, fig.margin=TRUE, echo=FALSE, results='asis'}
cat('Here is a margin code block with code-generated text and a plot.')
mtcars %>% ggplot(aes(mpg, disp)) + geom_point()
cat('The text stays in the main body.')
```


\vspace{10pt}
I can combine text and code in a footnote^[2+3=`r 2+3` \newline\vspace{10pt}], but I get footnote numbering, which I don't want.

```{marginfigure, echo=TRUE}
Here is a margin figure with inline code that doesn't work: 2+3=`r 2+3` \newline\vspace{10pt}
```


`r tufte::margin_note('This is a margin note. If I try to include inline code in it, I get an error because it "failed to tidy R code in chunk"')`

和输出:tufte-test.pdf

有任何想法吗?谢谢。

4

1 回答 1

3

标记的代码块marginfigure只是包装了 LaTeX 环境中的内容,称为marginfigure. 您可以自己执行此操作,然后将正确处理内联代码。

也就是说,你替换这个:

```{marginfigure, echo=TRUE}
Here is a margin figure with inline code that doesn't work: 2+3=`r 2+3` \newline\vspace{10pt}
```

有了这个:

\begin{marginfigure}
Here is a margin figure with inline code that *does* work: 2+3=`r 2+3` \newline\vspace{10pt}
\end{marginfigure}

你的第一个例子有点复杂。它需要分成三个部分:

\begin{marginfigure}
`r 'Here is a margin code block with code-generated text.'`
\end{marginfigure}

```{r block, fig.margin=TRUE, echo=FALSE}
mtcars %>% ggplot(aes(mpg, disp)) + geom_point()
```

\begin{marginfigure}
`r 'The text doesn\'t stay in the main body.'`
\end{marginfigure}

您要求 PDF 输出,但只是为了完整起见,如果您使用tufte::tufte_html的是 HTML 输出,则使用

<span class="marginnote">
Here is a margin figure with inline code that *does* work: 2+3=`r 2+3`
</span>
于 2019-02-27T16:19:26.270 回答