这是我之前发布的问题(在R中整洁地输出Sweave中的字符字符串元素)的延续。我有一个字符串数组,并尝试将每个元素输出到LaTeX中。我能够使用以下代码实现:
这为我提供了我所希望实现的正确输出:
然而,这导致了chapter_outcomes [\ i]上述语法的“意外输入”错误。
我尝试查看类似的帖子(LaTeX中的迭代, http://www.bytemining.com/2010/04/some-latex-gems-part-1-tikz-loops-and-more/),但它们的重点不同,我无法将其应用于解决我的问题。谢谢您的任何建议。
\documentclass[12pt,english,nohyper]{tufte-handout}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{longtable}
\usepackage{wrapfig}
\usepackaage{hyperref}
\usepackage{graphicx}
\usepackage[space]{grffile}
\usepackage{geometry}
\usepackage{enumitem}
\usepackage{pgffor}
\makeatletter
\makeatother
\begin{document}
<<include=FALSE>>=
library(ggplot2)
library(reshape2)
library(xtable)
@
\centerline{\Large\bf This is a test}
\vspace{1cm}
\noindent
My List:
\vspace{2mm}
.
<<echo=FALSE,results='asis'>>=
myList = c("A. This is the first item in my list.", "B. This is the second item in my list, and it will span across two lines because it is so long. This is the second item in my list, and it will span across two lines because it is so long.", "C. This is the third item in my list")
@
\begin{enumerate}[label=\Alph*., itemsep=-1ex]
\item \Sexpr{str_trim(unlist(strsplit(chapter_outcomes[1], "[.]"))[2])}
\item \Sexpr{str_trim(unlist(strsplit(chapter_outcomes[2], "[.]"))[2])}
\item \Sexpr{str_trim(unlist(strsplit(chapter_outcomes[3], "[.]"))[2])}
\end{enumerate}
\end{document}
这为我提供了我所希望实现的正确输出:
然而,我现在尝试将此迭代过程放入for循环中,因为我的chapter_outcomes字符串数组中可能不总是恰好有三个元素。我尝试了以下变体:
\begin{enumerate}[label=\Alph*., itemsep=-1ex]
\foreach \i in {\Sexpr{length(chapter_outcomes)}} {
\item \Sexpr{str_trim(unlist(strsplit(chapter_outcomes[\i], "[.]"))[2])}
}
\end{enumerate}
然而,这导致了chapter_outcomes [\ i]上述语法的“意外输入”错误。
我尝试查看类似的帖子(LaTeX中的迭代, http://www.bytemining.com/2010/04/some-latex-gems-part-1-tikz-loops-and-more/),但它们的重点不同,我无法将其应用于解决我的问题。谢谢您的任何建议。