问题描述
我正在使用 RStudio 的 rticle
包在 R 中写一篇文章使用 rmarkdown
包.在草稿模板中有一个选项
I am using rticle
package by RStudio to write an article in R using rmarkdown
package.In the draft template there is an option
...
preamble: >
% Any extra latex you need in the preamble
output: rticles::rjournal_article
...
我怀疑我可以添加诸如 \usepackage{package_name}
之类的行或设置一个文件名,在其中加载所有所需的 Latex 包.
Where I suspect I can add lines like \usepackage{package_name}
or set a file name in which I load all desired Latex packages.
第一种方法
我曾尝试将一个包添加到 preamble
部分,但出现错误
I've tried to add one single package to preamble
section like this but have stacked on an error
---
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}
但碰巧也有一个错误.
I've seen the same preamble
- ignoring behavior in this issue https://github.com/rstudio/rticles/issues/11, but there was no response for that.I've also tried to specify file named header.tex
that contains a line \usepackage{rotating}
in a last argument of a yaml like this but also there happend to be an error.
---
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
输出
When I specify yaml in a way it is intended to work for pdf_document
output
...
preamble: >
\usepackage{rotating}
output:
rticles::rjournal_article:
includes:
in_header: header.tex
...
我收到一个错误
Error in (function () :
unused (includes = list(in_header = "header.tex"))
编辑 2
即使是一个空的新文档,我也会遇到同样的错误
Even for an empty new document I get the same error
---
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 行:
The header.tex
document (which is in the same directory as saved empty new file) contains only 1 line:
\usepackage{rotating}
我知道常规 pdf_document
输出格式中的 in_header
选项(甚至可以使用 github 上的 RMD 扩展)但它看起来不适用于 rticles::rjournal_article
I am aware of in_header
option in regular pdf_document
output format (see even my files with RMD extensions on github) but it looks like to does not work with rticles::rjournal_article
编辑 3
我有兴趣添加除在渲染 .RMD 文件后生成的 RJwrappter.tex
文件中自动包含的那些胶乳包之外的其他胶乳包.
I am interested in adding other latex package than those that are included automatically in the RJwrappter.tex
file which is generated after render of the .RMD file.
\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.
Anyone maybe knows how to solve this?I am using MiKTeX 2.9.
推荐答案
我知道这个问题很老,但我遇到了和 Marcin 一样的问题,想分享我的解决方案.
I know this question's old but I just had the same problem as Marcin and wanted to share my solution.
对我有用的是更改 ASA 文章的 rticles
包中的 template.tex 文件.在模板的顶部,其中包含所有其他 \usepackage
命令,只需添加您的包即可.我遇到了和你一样的问题,第一个答案中提供的典型解决方案都不适合我.
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.
要编辑模板文件,请转到包库文件夹中的 rticles 目录(R 中的 .libPaths()
),然后打开 rmarkdown/templates/rjournal_article/resources/RJWrapper.tex.将您的包裹添加到所有其他包裹中.这应该适用于任何其他 *_article/resources/template.tex 文件.
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.
这篇关于如何将乳胶包从 R 中的文章包添加到 R 期刊模板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!