rnw

Use isotope latex-package inside Rnw (r-exams)

有些话、适合烂在心里 提交于 2021-01-28 21:02:53
问题 I want to load and use isotope package in my .Rnw file: \exname{foo} \extype{schoice} \exsolution{0001} \usepackage{isotope} \begin{question} Foo \isotope[A][Z]{H}\ bar \begin{answerlist} \item a \item b \item c \item d \end{answerlist} \end{question} But when I render it into Moodle's XML ( exams2moodle ) the \isotope disappear and appears only Foo bar . I'm using MathML rendering. How can I load and use correctly? 回答1: This short answer is: There is no way (that I know of) of rendering the

knitr kable: Text color in PDF from RNW is grey

↘锁芯ラ 提交于 2021-01-27 07:05:52
问题 When I create a table using the knitr::kable function within a RNW file, the text color of the table items in the PDF appears to be grey. I would like to change this to black. How can I do this? 回答1: \documentclass{article} \begin{document} <<>>= knitr::kable(cars[1:10,]) # grey @ <<results="asis">>= knitr::kable(cars[1:10,]) # black @ \end{document} By default, the output of kable will be wrapped in a knitrout environment where the text color ( fgcolor ) is set to grey ( rgb: 0.345, 0.345, 0

Put figure directly into Knitr document (without saving file of it in folder) Part 2

对着背影说爱祢 提交于 2019-12-25 04:15:29
问题 I am extending a question I recently posted here (Put figure directly into Knitr document (without saving file of it in folder)). I am writing an R package that generates a .pdf file for users that outputs summarizations of data. I have a .Rnw script in the package (here, my MWE of it is called test.Rnw). The user can do: 1) knit("test.Rnw") to create a test.tex file 2) "pdflatex test.tex" to create the test.pdf summary output file. The .Rnw file generates many images. Originally, these all

r knitr chunk options for figure height / width are not working

余生颓废 提交于 2019-12-25 04:12:02
问题 I used to use knitr in R to produce reports from the .Rnw format. In my reports I often put a plenty of plots and manipulated their size with the use of chunk optios, e.g.: \begin{figure}[h!] \centering <<fig.width=6, fig.height=4, out.width='.89\\linewidth'>>= plot(mtcars) @ \caption{} \end{figure} It was few months ago. Then I moved to another environment, reinstalled R and these options seem no longer work - the plot size stays unchanged on the PDF output ! Here comes all the lines of code

With knitr, preserve chunk options when purling chunks into separate files

核能气质少年 提交于 2019-12-24 01:28:11
问题 For teaching purposes, I would like to purl the chunks of my .Rnw file into separate files. This answer explains how to do it: How to purl each chunks in .Rmd file to multiple .R files using Knitr BUT the method does not preserve the chunk options. Since the chunks I have produce plots, it's important to preserve the fig.width and fig.height options. Ideally I would like a chunk that looks like this: <<plot, fig.width = 3, fig.height = 5, outwidth = '.75\\textwidth'>>= plot (1,1) @ to become

Knitr hook to postprocess pdf output?

最后都变了- 提交于 2019-12-11 04:12:36
问题 I have foo.Rnw file which uses the extrafont package for generating figures with text elements that use non-standard font families. After knitr calls pdflatex on my document, I want to run extrafont::embed_fonts on the resulting foo.pdf file. I can do this manually, but is there a way to do this from within knitr? (e.g., some knitr package option I can set to automatically call extrafont::embed_fonts after it knits my file and runs it through pdflatex) 回答1: As explained in this answer, it is

knitr Rnw latex: how to obtain a figure and caption in landscape mode that's full page width

微笑、不失礼 提交于 2019-12-11 02:49:52
问题 I am trying to produce a full-page figure along with a caption in landscape mode. The Rnw file below works fine if I omit "fig.cap='Caption Trial'", but not if the caption is used. Any help would be greatly appreciated. \documentclass{article} \usepackage{fullpage} \usepackage{pdflscape} \begin{document} \begin{landscape} <<test, out.width='1\\linewidth', fig.width=7, fig.height=4, fig.cap='Caption Trial'>>= par(mar=c(4, 4, .1, .1)); plot(1:10) @ \end{landscape} \end{document} 回答1: Try this:

xtable in .Rmd then knit as pdf in rstudio shows % comments

妖精的绣舞 提交于 2019-12-10 02:28:57
问题 I am making a PDF using Rstudio's 'knit PDF' option when writing an R Markdown (.Rmd) file. When creating a table using the xtable function, text commented in latex using the % is displayed in the pdf. This problem goes away when knitting a .Rnw file using latex and R. Below the is an example of an .Rmd file to be knitted as PDF and the equivalent .Rnw file, to knitted (as pdf, naturally). Their PDF results are identical, except for one line. Just above the table, the following is displayed:

Animated rgl graphs with knitr

。_饼干妹妹 提交于 2019-12-04 14:55:08
问题 I want to include animated rgl graphs in my .Rnw document through knitr . Here is my MWE: \documentclass{article} << label = setup, include = FALSE>>= opts_chunk$set(fig.path = 'figure/', cache = FALSE, dev = "pdf", fig.align = 'center', fig.show = 'hold', fig.width = 3, fig.height = 3, echo = TRUE, warning = FALSE, message = FALSE, size = 'footnotesize', comment=NA, results='hold') knit_hooks$set(par = function(before, options, envir){ if (before && options$fig.show!='none') par(mar = c(4, 4

Animated rgl graphs with knitr

只谈情不闲聊 提交于 2019-12-03 09:17:15
I want to include animated rgl graphs in my .Rnw document through knitr . Here is my MWE: \documentclass{article} << label = setup, include = FALSE>>= opts_chunk$set(fig.path = 'figure/', cache = FALSE, dev = "pdf", fig.align = 'center', fig.show = 'hold', fig.width = 3, fig.height = 3, echo = TRUE, warning = FALSE, message = FALSE, size = 'footnotesize', comment=NA, results='hold') knit_hooks$set(par = function(before, options, envir){ if (before && options$fig.show!='none') par(mar = c(4, 4, 0.1, 0.1), cex.lab = 0.95, cex.axis = 0.9, mgp = c(2, 0.7, 0), tcl = -0.3) } ) knit_hooks$set(rgl =