简体   繁体   中英

How to insert greek letter delta (∆) into header of flextable object?

I am using RMarkdown to create a word document (I need the output to be in .docx format).

I'd like to use flextable (or any other package) to format my headers properly.

I'm trying to get the greek symbol delta (∆) to display properly... it seems possible because in the help pages here ( https://davidgohel.github.io/flextable/articles/format.html#display-function ) the author successfully uses \μ to insert the "μ" symbol (and I can too if I use his code, below), but I can't get it to work for delta using \∆ or , if I replace \μ with either code below. The code I'm using produces this table, but I want to replace the highlighted bit with delta.

在此处输入图片说明

This is what I get when I try, for example, \∆ .

在此处输入图片说明

Any suggestions?

library(flextable)
if( require("xtable") ){
  mat <- round(matrix(c(0.9, 0.89, 200, 0.045, 2.0), c(1, 5)), 4)
  mat <- xtable(mat)
  ft <- xtable_to_flextable(x = mat, NA.string = "-")
  print(ft$col_keys)
  ft <- flextable::display(ft, i = 1, col_key = "X1", 
    pattern = "{{val}}{{pow}}", part = "header",
    formatters = list(val ~ as.character("R"), pow ~ as.character("2") ),
    fprops = list(pow = fp_text(vertical.align = "superscript", font.size = 8))
    )
  ft <- flextable::display(ft, i = 1, col_key = "X2", 
    pattern = "{{val}}{{pow}}", part = "header",
    formatters = list(val ~ as.character("\u03BC"), pow ~ as.character("x") ),
    fprops = list(pow = fp_text(vertical.align = "superscript", font.size = 8))
    )
  ft <- flextable::display(ft, i = 1, col_key = "rowname", 
    pattern = "{{val}}{{pow}}", part = "body",
    formatters = list(val ~ as.character("y"), pow ~ as.character("t-1") ),
    fprops = list(pow = fp_text(vertical.align = "subscript", font.size = 8))
    )
  ft <- set_header_labels(ft, X3 = "F-stat", X4 = "S.E.E", X5 = "DW", rowname = "")
  ft <- autofit(ft)
  ft
}

Update

I am getting closer thanks to a helpful suggestion from David, but (not being very familiar with flextable) I am getting strange behaviour when I try to modify the header in the way suggested:

library(magrittr)
library(flextable)
library(officer)
AICtable <- data.frame(Model = "test", Parameters = 9, AICc = 4000, dAICc = 0, w = 1)
v.epi.aic <- flextable(AICtable) %>% 
font(fontname = "Times New Roman", part = "all") %>% 
flextable::display(col_key = "dAICc", part = "header",
                                pattern = "{{D}}{{A}}{{cbit}}", 
                                formatters = list(D ~ as.character("D"),
                                                  A ~ as.character("AIC"),
                                cbit ~ as.character("c") ),
                                fprops = list(D = fp_text(font.family = "Symbol"),
                                              A = fp_text(font.family = "Times New Roman"),
                                cbit = fp_text(vertical.align = "subscript")))

v.epi.aic

Notice that column headers are now duplicated, and "AIC" appears before the "∆". The column names should be:

Model, Parameters, AICc, ∆AICc, w (and the "c" in the ∆AICc should be a subscript).

在此处输入图片说明

请使用“\\u394”而不是“\Δ”来生成大写增量符号

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM