【问题标题】:How to add a latex package to R Journal template from rticle package in R如何从 R 中的 rticle 包将乳胶包添加到 R Journal 模板
【发布时间】:2015-10-08 19:17:20
【问题描述】:

我正在使用 RStudio 的 rticle 包在 R 中使用 rmarkdown 包编写文章。 在草稿模板中有一个选项

...
preamble: >
  % Any extra latex you need in the preamble
output: rticles::rjournal_article
...

我怀疑我可以添加像\usepackage{package_name} 这样的行,或者设置一个文件名来加载所有需要的 Latex 包。

第一种方法

我尝试像这样将一个包添加到preamble 部分,但出现错误

---
title: Capitalized Title Here
author:
  - name: Author One
    affiliation: Affiliation
    address:
    - line 1
    - line 2
    email:  author1@work
  - name: Author Two
    affiliation: Affiliation
    address:
    - line 1
    - line 2
    email:  author2@work
abstract: >
  An abstract of less than 150 words.
preamble: >
  \usepackage{rotating}
  % Any extra latex you need in the preamble
output: rticles::rjournal_article
---

\begin{sidewaystable}
    \centering
    \caption{Your caption here}
   \begin{tabular}{ll}
    First First & First Second\\
    Second First & Second Second
    \end{tabular}
\end{sidewaystable}

第一种方法代码结束

BŁĄD: running 'texi2dvi' on 'RJwrapper.tex' failed

LaTeX errors:
D:\RTCGA.data\Untitled\Untitled.tex:11: LaTeX Error: Environment sidewaystable 
undefined.

See the LaTeX manual or LaTeX Companion for explanation.
Type  H <return>  for immediate help
D:\RTCGA.data\Untitled\Untitled.tex:13: Package caption Error: \caption outside
 float.

See the caption package documentation for explanation.
Type  H <return>  for immediate help
D:\RTCGA.data\Untitled\Untitled.tex:18: LaTeX Error: \begin{article} on input l
ine 20 ended by \end{sidewaystable}.

See the LaTeX manual or LaTeX Companion for explanation.
Type  H <return>  for immediate help
Dodatkowo: Warning message:
uruchomione polecenie '"C:\PROGRA~1\MIKTEX~1.9\miktex\bin\x64\texi2dvi.exe" --quiet --pdf "RJwrapper.tex" --max-iterations=20 -I "C:/PROGRA~1/R/R-32~1.0/share/texmf/tex/latex" -I "C:/PROGRA~1/R/R-32~1.0/share/texmf/bibtex/bst"' otrzymało status 1 
Wykonywanie wstrzymane

我也看到了相同的 preamble - 忽略此问题中的行为 https://github.com/rstudio/rticles/issues/11,但没有对此作出回应。 我还尝试指定名为header.tex 的文件,该文件在这样的yaml 的最后一个参数中包含\usepackage{rotating} 行,但也发生了错误。

---
title: Capitalized Title Here
author:
  - name: Author One
    affiliation: Affiliation
    address:
    - line 1
    - line 2
    email:  author1@work
  - name: Author Two
    affiliation: Affiliation
    address:
    - line 1
    - line 2
    email:  author2@work
abstract: >
  An abstract of less than 150 words.
preamble: > 
   \usepackage{rotating}
output: 
   rticles::rjournal_article:
   includes:
      in_header: header.tex
---
BŁĄD: running 'texi2dvi' on 'RJwrapper.tex' failed

LaTeX errors:
D:\RTCGA.data\rticle\rticle.tex:145: LaTeX Error: Environment sidewaystable und
efined.

See the LaTeX manual or LaTeX Companion for explanation.
Type  H <return>  for immediate help
D:\RTCGA.data\rticle\rticle.tex:147: Package caption Error: \caption outside fl
oat.

See the caption package documentation for explanation.
Type  H <return>  for immediate help
D:\RTCGA.data\rticle\rticle.tex:192: LaTeX Error: \begin{article} on input line
 20 ended by \end{sidewaystable}.

See the LaTeX manual or LaTeX Companion for explanation.
Type  H <return>  for immediate help
Dodatkowo: Warning message:
uruchomione polecenie '"C:\PROGRA~1\MIKTEX~1.9\miktex\bin\x64\texi2dvi.exe" --quiet --pdf "RJwrapper.tex" --max-iterations=20 -I "C:/PROGRA~1/R/R-32~1.0/share/texmf/tex/latex" -I "C:/PROGRA~1/R/R-32~1.0/share/texmf/bibtex/bst"' otrzymało status 1 
Wykonywanie wstrzymane

编辑

当我以某种方式指定 yaml 时,它适用于 pdf_document 输出

...
preamble: > 
   \usepackage{rotating}
output:
  rticles::rjournal_article:
    includes:
      in_header: header.tex
...

我收到一个错误

Error in (function ()  : 
  unused (includes = list(in_header = "header.tex"))

编辑 2

即使对于一个空的新文档,我也会遇到同样的错误

---
title: Capitalized Title Here
author:
  - name: Author One
    affiliation: Affiliation
    address:
    - line 1
    - line 2
    email:  author1@work
  - name: Author Two
    affiliation: Affiliation
    address:
    - line 1
    - line 2
    email:  author2@work
abstract: >
  An abstract of less than 150 words.
preamble: >
  % Any extra latex you need in the preamble
output:
  rticles::rjournal_article:
    includes:
      in_header: header.tex
---

Hello World

header.tex 文档(与保存的新空文件位于同一目录中)仅包含 1 行:

\usepackage{rotating}

我知道in_header 选项采用常规pdf_document 输出格式(甚至可以使用RMD extensions on github 查看我的文件),但它看起来不适用于rticles::rjournal_article

编辑 3

我有兴趣添加其他乳胶包,而不是自动包含在 .RMD 文件渲染后生成的 RJwrappter.tex 文件中的那些。

\documentclass[a4paper]{report}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{RJournal}
\usepackage{amsmath,amssymb,array}
\usepackage{booktabs}

%% load any required packages here


\begin{document}

%% do not edit, for illustration only
\sectionhead{Contributed research article}
\volume{XX}
\volnumber{YY}
\year{20ZZ}
\month{AAAA}

\begin{article}
  \input{rticle}
\end{article}

\end{document}

可能有人知道如何解决这个问题吗? 我正在使用 MiKTeX 2.9。

【问题讨论】:

  • 你有什么版本的 (La)TeX 系统?一个基本的 MickTeX?
  • MiKTeX 2.9 - 我已经编辑了我的问题

标签: r rstudio r-markdown


【解决方案1】:

我知道这个问题很老了,但我和 Marcin 遇到了同样的问题,想分享我的解决方案。

对我有用的是更改 ASA 文章的 rticles 包中的 template.tex 文件。在模板的顶部,他们有所有其他 \usepackage 命令,只需添加您的包。我遇到了与您相同的问题,并且第一个答案中提供的典型解决方案都不适合我。

要编辑模板文件,请转到包库文件夹中的 rticles 目录(R 中的.libPaths()),然后打开 rmarkdown/templates/rjournal_article/resources/RJWrapper.tex。将您的包裹添加到所有其他包裹中。这应该适用于任何其他 *_article/resources/template.tex 文件。

【讨论】:

【解决方案2】:

不,这是错误的。在 YAML 标头中声明您想要一个包含。

见rmarkdown reference:

---
title: "Habits"
output:
  pdf_document:
    includes:
      in_header: header.tex
      before_body: doc_prefix.tex
      after_body: doc_suffix.tex
---

我在几个文档中为此目的使用了header.tex。

编辑:当您似乎迷失在树林中时,这里是一个从默认用户抽象模板开始的简单示例:

---
title: "Title of Your Submission"
author:
 - name: FirstNameA LastNameA
keywords: First, Second, ... up to 5 keywords
output: 
  pdf_document:
    includes:
      in_header: marcin_header.tex
---

Content to be added here.

我加上了最简单的标题marcin_header.tex(放置在同一目录中)并且只包含

\usepackage{booktabs}

为我工作。

编辑 2:天哪。

---
title: Capitalized Title Here
author:
  - name: Author One
    affiliation: Affiliation
    address:
    - line 1
    - line 2
    email:  author1@work
  - name: Author Two
    affiliation: Affiliation
    address:
    - line 1
    - line 2
    email:  author2@work
abstract: >
  An abstract of less than 150 words.
preamble: >
  % Any extra latex you need in the preamble
  \usepackage{booktabs}
output: rticles::rjournal_article
---

## Introduction

Rest omitted.

【讨论】:

  • 我尝试像 @Dirk 这样指定 YAML。我编辑了我的帖子,但收到了一个错误。在我的第一个 YAML 规范中,rmarkdown 没有任何错误,但只有 from latex
  • 简化,简化,简化。创建一个“空”示例文档,您只需通过标题包含一个新包,以向自己证明这是有效的。然后在文档中慢慢添加您当前正在使用的功能。完成后,将其带到您的文档中。
  • 在发布之前我已经尝试过@Dirk。简单的新文档不起作用,我收到同样的错误:Error in (function () : unused argument (includes = list(in_header = "header.tex"))。我有使用 rmarkdown 的经验,我很震惊 pdf_document 的选项不适用于 rticles::rjournal_article
  • 适用于pdf_document,不适用于rticles::rjournal_article .. 在问题标题中有R Journal template。定期降价对我来说很好
  • 我再次编辑了我的问题,向您展示了我解决问题的第一种方法的代码。它看起来与您在编辑 2 中的方法完全相同(除了我使用旋转包)。您的代码看起来不会产生任何错误,因为只有纯文本。我的第一种方法也适用于纯文本,但是当我指定乳胶环境(以 \begin{sidewaystable} 开头的部分)时,它会因我在原始帖子中发布的错误而崩溃(在我第一次发布后仍然可以找到)方法的代码)。谢谢你的谈话:)
【解决方案3】:

正如 dash2 所提到的,您需要编辑您的文章模板之一以利用 header-includes 或 preamble 子句。例如,对于 rticles::aea_article 格式,模板可以是: /home/user/R/x86_64-pc-linux-gnu-library/3.3/rticles/rmarkdown/templates/aea_article/resources/template.tex

这是针对 linux 系统的,但是在您的计算机上有一个位置,无论操作系统是什么,存储 R 库的位置,您需要编辑此文件以包含 dash2 提供的 sn-p。

【讨论】:

    【解决方案4】:

    截至 10 月 16 日,没有简单的方法可以做到这一点。您需要做的是找到相关模板并对其进行编辑以包含以下行:

    $for(header-includes)$                                                                                                 
    $header-includes$                   
    $endfor$
    

    您可以通过查看源代码来找到模板,例如rjournal_article.

    【讨论】:

      【解决方案5】:

      我设法通过添加来包含浮动包

      header-includes: - \usepackage{float}

      在我的 yaml-header 开头的 frontiers-template 中

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-01-07
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多