If you directly implement with Chinese, it will throw error:
! Package inputenc Error: Unicode char \u8: not set up for use with LaTeX. Try running pandoc with –latex-engine=xelatex.Then you should put the following code in the head of the R markdown file:
title: Your File Title
author: Your Name
output:
pdf_document:
latex_engine: xelatex
- Though now it can be implemented, all Chinese disappear. So you should add a new latex file header to the R markdown file using the following code.
title: Your File Title
author: Your Name
outputs:
pdf_document:
includes:
in_header: header.tex
latex_engine: xelatex
- Now I will give you the content of header.tex file, which should be put in the same folder of your R markdown file.
\usepackage{xeCJK}
\setCJKmainfont{HanziPen SC} % Chinses Font
\setmainfont{Georgia}
\setromanfont{Georgia}
\setmonofont{Courier New}

本文介绍如何在R Markdown文件中正确使用LaTeX引擎XeLaTeX来显示中文字符,避免出现乱码错误。通过设置合适的字体及配置文件,确保中文内容能够正常呈现。
3177

被折叠的 条评论
为什么被折叠?



