如何将乳胶包添加到R中的rticle包中的R Journal模板

时间:2015-07-19 16:35:24

标签: r rstudio r-markdown

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

...
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,但没有回应。 我还尝试在这样的yaml的最后一个参数中指定名为header.tex的文件,其中包含一行\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

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

\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。

5 个答案:

答案 0 :(得分: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

编辑:当您在树林中迷路时,这是一个从默认的useR抽象模板开始的简单示例:

---
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.

答案 1 :(得分:2)

正如dash2所提到的,您需要编辑一个rticles模板以利用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提供的代码段。

答案 2 :(得分:2)

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

对我来说有用的是更改ASA文章的rticles包中的template.tex文件。在模板的顶部,他们拥有所有其他\usepackage命令,只需添加您的包。我遇到了同样的问题,第一个答案中提供的典型解决方案都没有为我工作。

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

答案 3 :(得分:1)

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

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

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

答案 4 :(得分:0)

我设法通过添加来包含float包

Android manifest: N: android=http://schemas.android.com/apk/res/android E: manifest (line=17) A: android:versionCode(0x0101021b)=(type 0x10)0x1 A: android:versionName(0x0101021c)="1.0" (Raw: "1.0") A: package="com.testing.sample.myapp" (Raw: "com.testing.sample.myapp") A: platformBuildVersionCode=(type 0x10)0x16 (Raw: "22") <---NOTE A: platformBuildVersionName="5.1.1-1819727" (Raw: "5.1.1-1819727") E: uses-sdk (line=22) A: android:minSdkVersion(0x0101020c)=(type 0x10)0x15 A: android:targetSdkVersion(0x01010270)=(type 0x10)0x16 E: application (line=26) A: android:label(0x01010001)=@0x7f0b0001 A: android:icon(0x01010002)=@0x7f030000 A: android:debuggable(0x0101000f)=(type 0x12)0xffffffff A: android:vmSafeMode(0x010102b8)=(type 0x12)0xffffffff ^ | ----------NOTE---------+

进入边界模板开头的yaml标头