(后续行动 用希伯来语制作 LaTeX 文档?(在 Sweave + RStudio 中))
尝试重现上述答案,在 Windows 7 下我按照这些说明操作但没有成功。
到目前为止,我得到的最好结果是一份包含正确希伯来语文本的文档,但 R 输出却是向后(即 RTL)的。这意味着整个文档都是右对齐的,甚至包括英语部分。
顺便说一句,我使用的是 knitr 函数,因为 sweave 根本不起作用。我的编码是 UTF-8。
我将非常感激任何建议或解决方案!
梅威瑟:
% 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}
(抱歉,系统不允许我上传图片...但相信我,整个页面是右对齐的,并且 R 代码是反转的)
答案1
由于我无法编译希伯来语文档(我可能需要安装某些字体),因此我猜测哪种方法可能有效。将其放入 LaTeX 序言中,看看是否有效:
\ifdefined\knitrout
\renewenvironment{knitrout}{
\begin{LTR}
}{
\end{LTR}
}
\else
\fi
环境LTR
被建议作者是 Alan Munn,我对此一无所知。