在R中的Sweave中整齐地输出字符串元素

时间:2015-06-22 14:12:42

标签: r sweave

我有一个字符串,我希望以更好的格式输出。目前,我的程序是这样的:

\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}

\makeatletter
\makeatother

\begin{document}
\SweaveOpts{concordance=TRUE}

<<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")
cat("\n\n\n")
cat(myList,sep="\n\n")
@

\end{document}

这导致输出如下所示:

(字符数组的每个元素的第一行是自动缩进的,这是我不想要的。另外,如果元素跨越多行,那么它的非第一行开始文本输出甚至更远 - 左对齐而不是在第一行之前)

我希望我的输出看起来更像是这样:

(现在,字符数组的每个元素的第一行不再自动缩进(每个元素的第一行开始于与标题“My List”相同的缩进。此外,对于任何跨越多个元素的元素在第一行中,非第一行有一个缩进,因此措辞开始于与第一行相同的位置。例如,在第二行(B)中,第一行中的“This”一词与该词具有相同的缩进第二行“第二”)) 我不确定如何完成这两个格式问题。非常感谢任何建议!

编辑:我接受了@NickK的建议,并使用了列表结构。它主要解决了我的问题。但是,它确实为我引入了另一个问题,我在一个新线程上打开了它。谢谢。 (Iterating through a character/string array in LaTeX

0 个答案:

没有答案