(Follow-up to Making LaTeX documents with Hebrew? (in Sweave + RStudio))
Trying to reproduce the above answer, I followed these instructions without success, under Windows 7.
The best result I got so far is a document containing correct Hebrew text, but backwards (meaning RTL) R output. It means that the whole document is right-aligned, even the English parts.
BTW, I was using the knitr function, as sweave was not functioning at all. My Encoding is UTF-8.
I would appreciate any tips or solution!
MWE:
% This document must be compiled with Sweave and xelatex (not pdflatex)
\documentclass{article}
\usepackage{booktabs}
\usepackage{caption}
\usepackage[noae]{Sweave} % you must load Sweave with the `noae` option
% load polyglossia late in the package load order, since the bidi package (which is
% loaded when an RTL language is set) redefines lots of package code.
\usepackage{polyglossia}
\setmainlanguage{hebrew}
\setotherlanguage{english}
\setmainfont{David CLM}
% for R work with Hebrew, it's important to have a mono font that supports
% the Hebrew script. Miriam Mono is one that I know of
\setmonofont[Script=Hebrew]{Miriam Mono CLM}
\title{\textenglish{Side-by-side xtables}}
\author{}
\date{}
\begin{document}
\maketitle
ראשית קצת קוד R כדי ליצור כמה נתונים.
<<>>=
myData <- matrix(c(19,89,23,23,74,44,16,39,67),ncol=3,byrow=TRUE)
colnames(myData) <- c("A","B","C")
rownames(myData) <- c("1","2","3")
myData2 <- myData * 2
@
כעת אנו שמים את הנתונים בשני צדדי על ידי צד טבלאות:
\begin{table}[htb]
\begin{minipage}{.45\textwidth}
\centering
\captionof{table}{\textenglish{First Table}}
<<echo=FALSE,results=tex>>=
library("xtable")
print(xtable(myData),
floating=FALSE,
hline.after=NULL,
add.to.row=list(pos=list(-1,0, nrow(myData)),
command=c('\\toprule\n','\\midrule\n','\\bottomrule\n')))
@
\end{minipage}
\begin{minipage}{.45\textwidth}
\centering
\captionof{table}{\textenglish{Second Table}}
<<echo=FALSE,results=tex>>=
print(xtable(myData2),
floating=FALSE,
hline.after=NULL,
add.to.row=list(pos=list(-1,0, nrow(myData2)),
command=c('\\toprule\n','\\midrule\n','\\bottomrule\n')))
@
\end{minipage}
\end{table}
\end{document}
(sorry, the system doesn't allow me to upload pics... but believe me, the whole page is right-aligned, and the R code is reversed)