【发布时间】:2020-05-30 06:50:24
【问题描述】:
我认为使用 bookdown 编写更长的报告/协议是个好主意,因为每个主题有一个文件而不是一个包含所有内容的 RMarkdown 文档会更舒服。现在我面临共享此文档的问题 - HTML 看起来最好(宽表被截断除外),但很难通过电子邮件发送给主管。我也不能指望任何人能够在他们的计算机上打开 ePub 格式,因此 PDF 将是最简单的选择。现在我的问题:
我的章节标题很长,这在 HTML 中无关紧要,但它们不适合 PDF 文档中的页眉。在 LaTeX 中我可以为它定义一个短标题,我也可以在 bookdown 中这样做吗?
我在代码块中包含使用knitr::include_graphics() 的图形文件,因此我通过块选项生成标题。对于某些数字,我无法避免在标题中使用下划线,但这在 LaTeX 中不起作用。有没有办法逃避实际有效的下划线(最好同时用于 HTML 和 PDF)?渲染后我的 LaTeX 输出如下所示:
\textbackslash{}begin\{figure\}
\includegraphics[width=0.6\linewidth,height=0.6\textheight]{figures/0165_HMMER} \textbackslash{}caption\{Output of HMMER for PA\_0165\}\label{fig:0165}
\textbackslash{}end\{figure\}
编辑
MWE 显示问题是下划线与out.height(或宽度)的百分比组合:
---
title: "MWE FigCap"
author: "LilithElina"
date: "19 Februar 2020"
output: pdf_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
## R Markdown
This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see <http://rmarkdown.rstudio.com>.
When you click the **Knit** button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:
```{r cars}
summary(cars)
```
## Including Plots
You can also embed plots, for example:
```{r pressure, echo=FALSE, fig.cap="This is a nice figure caption", out.height='40%'}
plot(pressure)
```
Note that the `echo = FALSE` parameter was added to the code chunk to prevent printing of the R code that generated the plot.
```{r pressure2, echo=FALSE, fig.cap="This is a not nice figure_caption", out.height='40%'}
plot(pressure)
```
【问题讨论】:
-
我无法重现您的第二个问题。你能提供一个minimal reproducible example吗?您可以使用
bookdown::pdf_document2作为输出格式,而不是完整的 bookdown 项目。 -
对不起,我之前没有注意到这一点。显然它是标题中的下划线和使用 out.width/height 的组合。