如何从R markdown到latex转换删除紧凑的标题?

时间:2017-07-26 16:43:02

标签: r latex r-markdown pandoc

我编写了自己的标题页,并通过R-markdown文件中的include加载。但是,这与pandoc标题冲突。我试图在R markdown yaml标题中找到设置,以便pandoc不会将以下代码插入到tex文件中。

% Create subtitle command for use in maketitle
\newcommand{\subtitle}[1]{
  \posttitle{
    \begin{center}\large#1\end{center}
    }
}

\setlength{\droptitle}{-2em}
  \title{}
  \pretitle{\vspace{\droptitle}}
  \posttitle{}
  \author{}
  \preauthor{}\postauthor{}
  \date{}
  \predate{}\postdate{}

pandoc文档或r markdown指南中没有明确指示如何禁用标题生成。任何帮助将不胜感激。

更新:特别是,我正在寻找能够让我继续使用\maketitle命令创建标题页的解决方案。这就是为什么我专注于这个我想要摆脱的特定代码。

3 个答案:

答案 0 :(得分:4)

我还使用我自己的标题页,其中包含乳胶/ pdf输出的rmarkdown文档。要删除标题,可以在名为in_header的文本文件中添加以下命令:

\AtBeginDocument{\let\maketitle\relax}

直接在Rmd文档中构建header.tex文件的可重现示例:

---
title: "RMarkdown No title Test"
author: "StatnMap"
date: "July 30, 2017"
output:
  pdf_document:
    includes:
      in_header: header.tex
--- 

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```

```{r rm_title_page, echo=FALSE}
head <- cat('
\\AtBeginDocument{\\let\\maketitle\\relax}
', file = "header.tex")

```

# Title 1
**Some text**

# Title 2
**Some text**

答案 1 :(得分:1)

我今天遇到了同样的问题。这就是我所做的。 (也许我会提出更好的解决方案来更新解决方案。)

该解决方案很笨但是有用。我现在无法在行之间设置任意间隔,因为我使用了\newline

---
title: "\\huge My Smart Title"
author: "\\newline \\Large My Smart Author"
date: "\\newline \\Large 2018-12-25"
output:
  pdf_document:
    includes:
      in_header: preamble.tex
    latex_engine: xelatex
---

下面是解决方案之前和之后的输出。

之前:

之后:

注意:   如果您不知道“作者”和“日期”的字体大小是\large,那么您可能会对上面两张图片中“作者”和“日期”的大小不同感到困惑。默认为\Large

END

答案 2 :(得分:1)

在YAML中使用compact-title: false

---
title: "This title is not compact"
author: "Test"
date: "2019 May 10"
output: pdf_document
compact-title: false
---

enter image description here