重新发布this from tex.stackexchange,因为tikzDevice标记在那里似乎相当不活跃。我希望没有人介意......
使用knitr和tikzDevice时遇到一些编译困难。 Compilataion工作,但我看到时间超过10分钟,这只是随着我的文档增长而增加(我正在撰写我的论文,目前编写一章需要10分钟,还有更多的章节要来!)。
如果我将设备设置为tikz以外的设备,那就没问题了。 不幸的是我需要tikz才能在我的R图中使用LaTeX。
我有一个主文件main.Rnw
,它使用例如每个章节作为子文档。 \Sexpr{knit_child('chapter3.Rnw')}
。
在章节文件中,我通过使用例如R包括图表等。 \Sexpr{knit_child('ch3-fig-nitrogenPH.Rnw')}
要在数字环境中插入。
我的主文件为knitr设置指定了以下选项:
<<setup, include=FALSE, cache=FALSE>>=
library(knitr)
library(tikzDevice)
library(tidyverse)
library(ggpubr)
library(multcomp)
library(multcompView)
library(DescTools)
plotTextSize <- 8
cbbPalette<-c("#E69F00", "#56B4E9", "#009E73", "#0072B2", "#D55E00", "#CC79A7")
opts_knit$set(child.command = 'include')
opts_chunk$set(dev = 'tikz', external=TRUE)
opts_chunk$set(fig.align='center', fig.pos='!htbp', fig.width=5.5, fig.height=4, out.width="5.5in", out.height="4in")
options(tikzDefaultEngine='xetex')
options(tikzXelatexPackages = c(
getOption('tikzXelatexPackages'),
"\\usepackage{amsmath,amssymb,amsfonts}",
"\\usepackage{tikz}",
"\\usetikzlibrary{calc}",
"\\usepackage[british]{babel}",
"\\selectlanguage{british}"
))
options(tikzMetricPackages = c(
"\\usetikzlibrary{amssymb}",
"\\usetikzlibrary{calc}",
"\\usepackage{hyperref}"
))
knit_hooks$set(document = function(x) {sub('\\usepackage[]{color}', '\\usepackage{xcolor}', x, fixed = TRUE)})
@
最后,另外一件事表明我在某处出了问题,就是当我尝试使用它时tikz忽略了点数arurmet,例如dev.args=list(pointsize=10)
无效。请参阅我之前的问题https://tex.stackexchange.com/questions/408390/setting-font-size-in-tikzdevice。
如果有人能指出我正确的方向来解决这个问题,我将非常感激。
我将尝试整理一个能够复制问题的MWE。
我正在使用这些包:
% -*- program: xelatex -*-
\documentclass[12pt,twoside,headings=big,open=right]{scrreprt}
\usepackage{scrhack,graphicx,subcaption,nomencl,setspace,xltxtra,fontspec,microtype,csquotes,tocbibind,xspace,floatrow,tikz,textcomp,rotating,xpatch,amssymb,amsfonts,xcolor,xunicode}
\defaultfontfeatures{Ligatures=TeX}
\graphicspath{ {images/} }
\usepackage[a4paper,width=150mm,top=25mm,bottom=25mm,bindingoffset=6mm]{geometry}
\usepackage[british]{babel}
编辑: 我的sessionInfo():
R version 3.4.3 (2017-11-30)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: macOS High Sierra 10.13.3
Matrix products: default
BLAS: /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/3.4/Resources/lib/libRlapack.dylib
locale:
[1] en_GB.UTF-8/en_GB.UTF-8/en_GB.UTF-8/C/en_GB.UTF-8/en_GB.UTF-8
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] DescTools_0.99.23 multcompView_0.1-7 multcomp_1.4-8 TH.data_1.0-8 MASS_7.3-48
[6] survival_2.41-3 mvtnorm_1.0-7 ggpubr_0.1.6 magrittr_1.5 forcats_0.2.0
[11] stringr_1.2.0 dplyr_0.7.4 purrr_0.2.4 readr_1.1.1 tidyr_0.8.0
[16] tibble_1.4.2 ggplot2_2.2.1.9000 tidyverse_1.2.1 tikzDevice_0.10-5 knitr_1.19
loaded via a namespace (and not attached):
[1] Rcpp_0.12.15 lubridate_1.7.1 lattice_0.20-35 zoo_1.8-1 assertthat_0.2.0
[6] digest_0.6.15 psych_1.7.8 R6_2.2.2 cellranger_1.1.0 plyr_1.8.4
[11] httr_1.3.1 pillar_1.1.0 rlang_0.1.6.9003 lazyeval_0.2.1 curl_3.1
[16] readxl_1.0.0 rstudioapi_0.7 Matrix_1.2-12 devtools_1.13.4 splines_3.4.3
[21] foreign_0.8-69 munsell_0.4.3 tinytex_0.3.1 broom_0.4.3 compiler_3.4.3
[26] modelr_0.1.1 pkgconfig_2.0.1 mnormt_1.5-5 manipulate_1.0.1 expm_0.999-2
[31] codetools_0.2-15 crayon_1.3.4 withr_2.1.1.9000 grid_3.4.3 nlme_3.1-131
[36] jsonlite_1.5 gtable_0.2.0 git2r_0.21.0 scales_0.5.0.9000 cli_1.0.0
[41] stringi_1.1.6 reshape2_1.4.3 bindrcpp_0.2 xml2_1.2.0 boot_1.3-20
[46] sandwich_2.4-0 tools_3.4.3 glue_1.2.0 hms_0.4.1 parallel_3.4.3
[51] yaml_2.1.16 colorspace_1.3-2 filehash_2.4-1 rvest_0.3.2 memoise_1.1.0
[56] bindr_0.1 haven_1.1.1