简体   繁体   English

格式代码块编织器

[英]format code chunks knitr

I'm into my first attempt at using knitr to produce some reports for teachers based on their standardized test scores. 我是第一次尝试使用knitr根据他们的标准化考试成绩为教师制作一些报告。 Because the number of exams tied to each teacher is different, I'm trying to use a loop within a code chunk to produce this portion of the reports. 因为与每位教师相关的考试数量不同,我试图在代码块中使用循环来生成这部分报告。 As a result, I'm finding it hard to format the text and make it readable. 结果,我发现很难格式化文本并使其可读。 Any advice on how I can get some simple centering and/or bold to make the pages more readable. 关于如何获得一些简单的居中和/或粗体以使页面更具可读性的任何建议。 Here's a stripped down example: 这是一个精简的例子:

 \documentclass{article}

    \begin{document}
    \title{TEST RESULTS}
    \maketitle


    <<Categories, echo = FALSE, message = FALSE, results = "asis">>=
    TestCode = c("math","art", "reading")
    for(i in unique(TestCode)){
      cat("\n\n\\pagebreak\n")
      cat("Exam :",i,"\n\n","TEXTY TEXT TEXT")
    }

    @


\end{document}

The goal is to produce a page for each test. 目标是为每个测试生成一个页面。 I would like to either be able to bold the exam title, bold the exam title, or make the text larger. 我想要能够加粗考试题目,加粗考试题目,或者使文字更大。 I don't think I can use the latex commands like \\section*{} to achieve this as R doesn't interpret these escape characters. 我不认为我可以使用像\\section*{}这样的乳胶命令来实现这一点,因为R不解释这些转义字符。

Thanks for your help! 谢谢你的帮助!

You can use \\section , you just need to be careful with the escaping. 你可以使用\\section ,你只需要小心逃脱。 cat(sprintf("\\\\section*{Exam: %s}", i) should do the trick. cat(sprintf("\\\\section*{Exam: %s}", i)应该这样做。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM