[R] Centering R output in Sweave/LaTeX

cls59 sharpsteen at mac.com
Fri May 15 02:21:01 CEST 2009




Jean-Louis Abitbol-2 wrote:
> 
> Good Day to All,
> 
> When sweaving the following:
> 
> \begin{table}
> \centering
> <<echo=FALSE>>=
> ftable(ifmtm$type, ifmtm$gender, ifmtm$marche , ifmtm$nfic,
> dnn=c("Type","Gender","Ambulant","Visit"))
> @
> \caption{Four-way cross-tabulation on all data}
> \label{tab:crosstab}
> \end{table}
> 
> the output of ftable is not centered while the latex caption is.
> 
> Is there a way to center the R output in this setting ?
> 
> Thanks for any help and best wishes, JL
> 
> 

I believe the problem arises because the R output is encased in fancyvrb
Verbatim environments after processing by Sweave. These environments have
implement their own justification rules which override the alignment
specified by \centering. A way to get around this would be to wrap the
output in another environment that does respect justification such as the
minipage:

\begin{table}
\centering

\begin{minipage}{0.5\textwidth}

<<echo=FALSE>>=
ftable(ifmtm$type, ifmtm$gender, ifmtm$marche , ifmtm$nfic,
dnn=c("Type","Gender","Ambulant","Visit"))
@

\end{minipage}


\caption{Four-way cross-tabulation on all data}
\label{tab:crosstab}
\end{table}


You may have to adjust the width of the minipage in order to achieve the
results you desire. Hope this helps!

-Charlie


-----
Charlie Sharpsteen
Undergraduate
Environmental Resources Engineering
Humboldt State University
-- 
View this message in context: http://www.nabble.com/Centering-R-output-in-Sweave-LaTeX-tp23525507p23551392.html
Sent from the R help mailing list archive at Nabble.com.




More information about the R-help mailing list