Outputting character string elements neatly in Sweave in R

164 views Asked by At

I have a character string that I would like to output in a better format. Currently, my program is something like this:

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

This leads to an output that looks like this:

(The first line of each element of the character array is auto-indented, which I do not want. Also, if the element spans multiple lines, then its non-first lines begin text output even further-left aligned than the preceding first line)

What I would like my output to look like is more like this:

(Now, the first line of each element of the character array is no longer auto-indented (each element's first line begins at the same indentation as the title "My List". Also, for any element that spans more than one line, the non-first lines have an indent so that the wording begins at the same location as the first line. For example in the second element (B), the word "This" from the first line has the same indentation as the word "second" on the second line)) I am unsure how to accomplish these two format issues. Any advice is greatly appreciated!

EDIT: I took the advice of @NickK, and used the list structure. It mostly solved my problem. However, it did introduce another problem for me, which I opened up on a new thread. Thank you. (Iterating through a character/string array in LaTeX)

0

There are 0 answers