![](/img/trans.png)
[英]How to create table in rmarkdown using greek letters in column headers?
[英]How can I add greek letters to cells in my Rmarkdown table using kable?
我正在嘗試在 R Markdown 中呈現一個表格,其中包含幾個包含希臘字母的單元格。 我使用以下代碼生成表:
table <- readxl::read_excel("path/to/table.xlsx",
sheet = "data")
table %>%
knitr::kable(booktabs = TRUE)
雖然控制台中的 output 正是我想要的,但當我嘗試將文件編織到 PDF 時,我收到以下錯誤消息:
! LaTeX Error: Unicode character κ (U+03BA)
not set up for use with LaTeX.
我需要把所有希臘字母放在桌子上。 我找到了有關在標題中獲取希臘字母的信息,但沒有找到關於讓它們在表格正文中工作的信息。 實現這一目標的最佳方法是什么?
下面是我嘗試渲染的數據示例。
任何幫助將不勝感激!
編碼問題是永恆的。
我可以建議你這個解決方案。
不是那么優雅,但它確實有效。
控制台中的步驟:
激活希臘語言環境:
Sys.setlocale("LC_CTYPE", "greek")
閱讀 excel 文件:
table <- readxl::read_excel("table.xlsx", sheet = "N1")
為 LaTeX 生成代碼:
table %>% knitr::kable(booktabs = TRUE, "latex")
現在我們可以轉移到 rmd 文件:
一個簡單的例子:
---
title: "Table"
output:
pdf_document:
latex_engine: xelatex
header-includes:
- \usepackage{polyglossia}
- \setotherlanguage{greek}
- \newfontfamily\greekfont[Script=Greek,Ligatures=TeX]{Times New Roman}
- \usepackage{booktabs}
---
Beautiful table:
\begin{greek}
\begin{tabular}{ll}
\toprule
Object1 & Object2\\
\midrule
ββ & λ\\
α & φ\\
\bottomrule
\end{tabular}
\end{greek}
Output:
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.