- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我将 r markdown 与 knitr 一起使用来生成 tex 文档。但是,有几次我遇到了一个问题,我在序言中使用“mystyles.txt”文档加载的包与 knitr 自动加载的包冲突。错误看起来因问题而异,但它始终以“选项冲突”为特征。
我相信我明白这个问题的来源(我认为)——我只是不知道如何解决它。当我尝试使用 mystyles.txt 中的包时,例如 \usepackage[pdftex]{graphicx}
或 \usepackage[table]{xcolor}
,我收到选项冲突错误,因为默认情况下这些包已经加载而没有选项。
但是,这会带来一个问题,因为我需要使用我指定的确切选项加载包。这意味着我需要以某种方式抑制或修改由 r markdown/knitr 自动完成的包加载。
例如,knitr 会自动调用 \usepackage{graphicx}
.如果在序言中有某种方法可以指定它是 \usepackage[pdftex]{graphicx}
,然后我可以从 mystyles.txt 中删除相同的行,我会很好。不幸的是,我无法找到有关此问题的任何文档,以下引用指南未提供任何见解:http://rmarkdown.rstudio.com/RMarkdownReferenceGuide.pdf .
有谁知道如何处理这个问题?
-保罗
最佳答案
我今天早上刚遇到这个问题,我的解决方案是使用自定义模板。
This document 解释了 PDF 输出的各种选项,您会看到有一个用于设置自定义模板大约 1/3 的示例 YAML header :
---
title: "My document"
output:
pdf_document:
template: my_template.tex
---
my_template.tex
模板文件。上一页链接到Knitr使用的
default template;只需将其复制并粘贴到
my_template.tex
文件中并删除冲突的代码位。
\documentclass[$if(fontsize)$$fontsize$,$endif$$if(lang)$$babel-lang$,$endif$$if(papersize)$$papersize$,$endif$$for(classoption)$$classoption$$sep$,$endfor$]{$documentclass$}
\usepackage{hyperref}
\hypersetup{unicode=true,
$if(title-meta)$
pdftitle={$title-meta$},
$endif$
$if(author-meta)$
pdfauthor={$author-meta$},
$endif$
$if(subtitle)$
pdfsubject={$subtitle$},
$endif$
$if(keywords)$
pdfkeywords={$for(keywords)$$keywords$$sep$; $endfor$},
$endif$
$if(colorlinks)$
colorlinks=true,
linkcolor=$if(linkcolor)$$linkcolor$$else$Maroon$endif$,
citecolor=$if(citecolor)$$citecolor$$else$Blue$endif$,
urlcolor=$if(urlcolor)$$urlcolor$$else$Blue$endif$,
$else$
pdfborder={0 0 0},
$endif$
breaklinks=true}
\urlstyle{same} % don't use monospace font for urls
$if(listings)$
\usepackage{listings}
$endif$
$if(lhs)$
\lstnewenvironment{code}{\lstset{language=Haskell,basicstyle=\small\ttfamily}}{}
$endif$
$if(highlighting-macros)$
$highlighting-macros$
$endif$
$if(verbatim-in-note)$
\usepackage{fancyvrb}
\VerbatimFootnotes % allows verbatim text in footnotes
$endif$
$if(tables)$
\usepackage{longtable,booktabs}
$endif$
$if(graphics)$
\usepackage{graphicx,grffile}
\makeatletter
\def\maxwidth{\ifdim\Gin@nat@width>\linewidth\linewidth\else\Gin@nat@width\fi}
\def\maxheight{\ifdim\Gin@nat@height>\textheight\textheight\else\Gin@nat@height\fi}
\makeatother
% Scale images if necessary, so that they will not overflow the page
% margins by default, and it is still possible to overwrite the defaults
% using explicit options in \includegraphics[width, height, ...]{}
\setkeys{Gin}{width=\maxwidth,height=\maxheight,keepaspectratio}
$endif$
$if(links-as-notes)$
% Make links footnotes instead of hotlinks:
\renewcommand{\href}[2]{#2\footnote{\url{#1}}}
$endif$
$if(strikeout)$
\usepackage[normalem]{ulem}
% avoid problems with \sout in headers with hyperref:
\pdfstringdefDisableCommands{\renewcommand{\sout}{}}
$endif$
$if(title)$
\title{$title$$if(subtitle)$\\\vspace{0.5em}{\large $subtitle$}$endif$}
$endif$
$if(author)$
\author{$for(author)$$author$$sep$ \and $endfor$}
$endif$
\date{$date$}
$for(header-includes)$
$header-includes$
$endfor$
$if(subparagraph)$
$else$
% Redefines (sub)paragraphs to behave more like sections
\ifx\paragraph\undefined\else
\let\oldparagraph\paragraph
\renewcommand{\paragraph}[1]{\oldparagraph{#1}\mbox{}}
\fi
\ifx\subparagraph\undefined\else
\let\oldsubparagraph\subparagraph
\renewcommand{\subparagraph}[1]{\oldsubparagraph{#1}\mbox{}}
\fi
$endif$
\begin{document}
$if(title)$
\maketitle
$endif$
$if(abstract)$
\begin{abstract}
$abstract$
\end{abstract}
$endif$
$for(include-before)$
$include-before$
$endfor$
$if(toc)$
{
$if(colorlinks)$
\hypersetup{linkcolor=$if(toccolor)$$toccolor$$else$black$endif$}
$endif$
\setcounter{tocdepth}{$toc-depth$}
\tableofcontents
}
$endif$
$if(lot)$
\listoftables
$endif$
$if(lof)$
\listoffigures
$endif$
$body$
$if(natbib)$
$if(bibliography)$
$if(biblio-title)$
$if(book-class)$
\renewcommand\bibname{$biblio-title$}
$else$
\renewcommand\refname{$biblio-title$}
$endif$
$endif$
\bibliography{$for(bibliography)$$bibliography$$sep$,$endfor$}
$endif$
$endif$
$if(biblatex)$
\printbibliography$if(biblio-title)$[title=$biblio-title$]$endif$
$endif$
$for(include-after)$
$include-after$
$endfor$
\end{document}
关于r - 如何控制 RMarkdown/knitr 加载的默认包以避免选项冲突,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28776237/
我正在用 Bookdown 写一份报告,我有兴趣水平地复制一系列图片,并用一个描述所有图片的标题。如果我不定义 fig.cap,我会得到正确的图片,如下所示: ```{r, out.width = "
我用过dplyr对于某些分析和特定代码,完成操作大约需要 30 秒。在生成的 HTML 中,我得到了类似这样的很长的输出(再现最后几行): |=============================
我的 last two问题只是令人尴尬,但我相信这是真正的交易。我的系统是新安装的,所以除了操作系统之外的版本都是最新的:Windows 7 SP1、R-3.0.1、Lyx 2.0.6、knitr 1
我找不到将语法上可接受的 RStudio 样式折叠插入外部 R 代码文件的方法,该文件设置为从 knitr 文档中使用。或者我错过了什么。有几种方法可以做到这一点:1) 允许代码头,例如: ## @k
我有一个包含以下代码的小书本“书”: A concept map is a diagram that shows 'ideas' and the relationship between those
像这样的东西,但它不起作用: ```{r examples, engine="bash"} export EXAMPLES="example/path" ``` ```{r example1,
我是 latex 和 knitr 的新手,当我使用 echo=FALSE 时,R block 的输出有问题。下面的 .Rnw 代码按预期工作,即输出有 1. some code 2.
有没有办法使用 .Rmd 文件 直接在 Jupyter 中?换句话说,有没有办法让 jupyter 渲染这样的文件:https://github.com/yihui/knitr-examples/bl
是否可以在 markdown 文件中使用 knitr 的 pandoc() 函数和嵌入的 pandoc 配置来更改默认的 pandoc latex 模板选项? 例如,如果我在 foo.md 的开头使用
我不熟悉使用 rmarkdown 和 knitr 来制作 .docx word 文档。 rmarkdown 引用指南指出,使用 -- 给出一个破折号,而 --- 给出一个破折号。 如果我将我的 .Rm
我想知道是否有一种自动化的方法可以使评论不打印在输出中。现在,我正在使用以下内容来省略评论: >= ## load relimp package library(relimp) ## calculat
我已经根据文档在 Knitr 上添加了自定义语言引擎。 require(knitr) knit_engines$set(upper = function(options) { code <- pa
我正在使用 Rmarkdown 生成一个 PDF 文档,我想在其中手动定义图形编号。 下面是一个 block 的例子: ```{r chunk26, fig.cap = "Fig. 5.3 My fi
这可能是一个极端情况,但我正在尝试使用 knitr 创建一个投影仪演示文稿,我想在其中使用不同的公式作为函数的参数来显示代码块。我发现当使用覆盖时,代码块中的波浪号消失了。有没有办法让它们显示? 这是
我尝试编译 YiHui 的 BIG5 example (有中文内容的knitr)。我使用了 Mac OSX snowleopard、最新的 RStudio、pdfLatex(结果与 XeLatex 相
这听起来像是一个愚蠢的问题,但是当我使用 RStudio 服务器从 Rmd 文件编译 pdf 文档时,我想知道 .tex 文件保存在哪里。 我添加了 keep_tex 选项,因此 Rmd 的标题如下所
在 knitr可以在代码块中使用其他语言。例如,我们可以使用: ```{python} Some python code ``` 我们可以使用 R引擎内联`r一些R代码` 中是否可以使用其他语言?内联
例如,在编写演讲幻灯片时,我们经常会遇到这样一种情况,我们希望内联代码输出为 source code = result。 .所以例如 "foofoofoo qt(p = 0.95, df = 24)
有没有办法,在 knitr 中将 fig.cap 移动到图形上方?我需要上面的它们,以便当为某个表选择图列表的超链接时,它会导航到图。 Right now the caption and thus h
如果它在同一目录中,我可以对子文档使用以下代码。 >= @ 如果子文档不在主文档的同一目录中,我想知道如何使用子文档。预先感谢您的帮助和时间。 最佳答案 这可以被认为是一个错误。现在我已经把它修好了
我是一名优秀的程序员,十分优秀!