How to add a latex package to R Journal template from rticle package in R

久未见 提交于 2019-12-01 22:23:36

I know this question's old but I just had the same problem as Marcin and wanted to share my solution.

What worked for me was changing the template.tex file in the rticles package for the ASA article. At the top of the template, where they have all the other \usepackage commands, just add your package(s). I had the same problem that you did and neither of the typical solutions as provided in the first answer worked for me.

To edit the template file, go to the rticles directory in your package library folder (.libPaths() in R), then open up rmarkdown/templates/rjournal_article/resources/RJWrapper.tex. Add your package amongst all the others. This should work for any of the other *_article/resources/template.tex files.

No, that is wrong. In the YAML header declare that you want an include.

See the rmarkdown reference:

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

I have used header.tex for this purpose in several documents.

Edit: As you appear to get lost in the woods, here is a simplyfied example started from the default useR abstract template:

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

which I coupled with the simplest possible header called marcin_header.tex (placed in the same directory) and containing just

\usepackage{booktabs}

Works for me.

Edit 2: Oh boy.

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

As dash2 mentioned you need to edit one of your rticles templates to take advantage of the header-includes or preamble clause. For example for the rticles::aea_article format the template could be in: /home/user/R/x86_64-pc-linux-gnu-library/3.3/rticles/rmarkdown/templates/aea_article/resources/template.tex

This is for a linux system, but there's a location on your computer, whatever the OS, where R libraries are stored and you need to edit this file to include the snippet that dash2 provided.

There is no easy way to do this, as of Oct 16. What you need to do is find the relevant template and edit it to include the lines:

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

You can find the template by looking at the source code for e.g. rjournal_article.

I managed to include the float package by adding

header-includes: - \usepackage{float}

into my yaml-header at the beginning of the frontiers-template

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!