我正在尝试在我的Tufte Latex文档中添加一个边距注释,该文档部分是由r代码生成的,但没有成功。设置为在页边空白处打印的代码块似乎只将图形放在那里,而不是文本或表格。如果用tufte::marginfigure()调用的保证金注释中包含内联代码,则会抛出错误。和边距图块忽略内联代码。我已经成功地在页边空白处打印了代码生成的文本和脚注,但是我得到了脚注编号,这是我不想要的。我想过关闭那个脚注上的编号,但还没能做到。
下面是一个例子:
---
title: "Tufte Test"
author: "Neal"
date: "`r Sys.Date()`"
output:
tufte::tufte_handout: default
---
```{r setup, include=FALSE}库(Tufte)
库(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(‘这是一个包含代码生成的文本和绘图的页边距代码块。’)
mtcars %>% ggplot(aes(mpg,disp)) + geom_point()
cat(‘文本保留在正文中。’)
\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}这是一个包含不起作用的内联代码的边距图: 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"')`有什么想法吗?谢谢。
发布于 2019-02-28 00:19:26
标记为marginfigure的代码块只是包装了名为marginfigure的LaTeX环境中的内容。您可以自己做这件事,然后内联代码将被正确处理。
也就是说,您可以替换以下内容:
```{marginfigure, echo=TRUE}这是一个包含不起作用的内联代码的边距图: 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>https://stackoverflow.com/questions/54906964
复制相似问题