RMarkdown輸出PDF時,如何跑出中文字

1,746 views
Skip to first unread message

Jolin Hsieh

unread,
May 21, 2015, 9:33:21 PM5/21/15
to taiwa...@googlegroups.com
各位前輩好,

想請問R Markdown要輸出PDF檔時,如何跑出中文字?

感謝各位前輩~

WEPA ^_^

unread,
May 24, 2015, 8:17:31 AM5/24/15
to taiwa...@googlegroups.com, jo...@weatherrisk.com
Hi Jolin,

請說明您的操作環境與使用哪些語法有問題.

Jolin Hsieh於 2015年5月22日星期五 UTC+8上午9時33分21秒寫道:
各位前輩好,

想請問R Markdown要輸出PDF檔時,如何跑出中文字?

感謝各位前輩~

Jolin Hsieh

unread,
May 25, 2015, 12:05:13 AM5/25/15
to taiwa...@googlegroups.com

WEPA大大,

>>>>>>操作環境如下:

Rmd檔設定為UTF-8格式編碼


>>>>>>語法如下:

---
title: "BestSales"
author: "weatherR"
date: "Monday, May 12, 2015"
output: beamer_presentation
---

## Operation procedure

- Get past data
- Data analysis
- Meteorology correlation
- Forecast equation
- Predict your data

## Background data analysis Plot
1. Value of right chart converge on **1000~2000**.
2. A annual cycles.
3. Hi!哈囉!



>>>>>>Error訊息:

processing file: Preview-1674768472c8.Rmd
  |.................................................................| 100%
  ordinary text without R code



"C:/Program Files/RStudio/bin/pandoc/pandoc" Preview-1674768472c8.utf8.md --to beamer --from markdown+autolink_bare_uris+ascii_identifiers+tex_math_single_backslash-implicit_figures --output Preview-1674768472c8.pdf --template "D:\Tony Cheng\R\win-library\3.2\rmarkdown\rmd\beamer\default.tex" --highlight-style tango 
! Package inputenc Error: Unicode char \u8:哈 not set up for use with LaTeX.

See the inputenc package documentation for explanation.
Type  H <return>  for immediate help.
 ...                                              
                                                  
l.89 \end{frame}

Try running pandoc with --latex-engine=xelatex.
pandoc.exe: Error producing PDF from TeX source
���~: pandoc document conversion failed with error 43
���~: Warning message:
���椤�R�O '"C:/Program Files/RStudio/bin/pandoc/pandoc" Preview-1674768472c8.utf8.md --to beamer --from markdown+autolink_bare_uris+ascii_identifiers+tex_math_single_backslash-implicit_figures --output Preview-1674768472c8.pdf --template "D:\Tony Cheng\R\win-library\3.2\rmarkdown\rmd\beamer\default.tex" --highlight-style tango' �w�����A 43 
��������



感謝各位前輩多多指教~~

Jolin Hsieh

unread,
May 27, 2015, 1:51:39 AM5/27/15
to taiwa...@googlegroups.com

WEPA ^_^

unread,
May 27, 2015, 11:34:52 AM5/27/15
to taiwa...@googlegroups.com, jo...@weatherrisk.com
Hi Jolin,

謝謝提供參考網址.

Jolin Hsieh於 2015年5月27日星期三 UTC+8下午1時51分39秒寫道:

WEPA ^_^

unread,
Jul 27, 2024, 10:38:21 AMJul 27
to R軟體使用者論壇
2024.7.27 更新:

使用環境: Windows 11 + R -4.4.1 +  RStudio-2024.04.02

問題: RStudio \ R Markdown \ Knit to PDF 會有錯誤訊息或是中文字型建立PDF錯誤

分析: 參考以下三步驟即可輸出為 PDF, 如果無中文字型需求, 僅須步驟1, 2.

1. 安裝 tinytex

install.packages("tinytex")

2. 安裝 TinyTeX

tinytex::install_tinytex()

3. 設定 .Rmd 檔案的標題 header-includes:, 本例 author 以中文輸入測試

---
title: "HelloWorld"
author: "李明昌"
date: "2024-07-27"
header-includes:
  - \usepackage{ctex}

output:
  pdf_document:
  includes:
    keep_tex: yes
    latex_engine: xelatex

  html_document: default
  word_document: default
---
# end
WEPA ^_^ 在 2015年5月27日 星期三晚上11:34:52 [UTC+8] 的信中寫道:
Reply all
Reply to author
Forward
0 new messages