Outputting character string elements neatly in Sweave in R

泪湿孤枕 提交于 2019-12-08 11:15:08

问题


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)

来源:https://stackoverflow.com/questions/30982161/outputting-character-string-elements-neatly-in-sweave-in-r

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!