I want to build a table that has html code to show emphasis for a column heading. Some values in the column contain the "<" symbol. I am only able to either show the emphasis on the column heading without the values or show the values in the column without the column heading formatted correctly, but not both.
Below is a reproducible example to illustrate and I have attached two images to show how the table output changes if escape = TRUE, which is the default behavior compared to escape = FALSE`. Does anyone have any suggestions. Thanks!
Thank you for the suggestion. Can gt handle two variables as below? I need to be able to show the same header values for different variables. You solution does work, but I don't know how to deal with two variables that have the same subheader values in gt.
gt() expects unique column names to be passed, so here I've used the clean_names() function from the janitor package to do this (it adds _2 to the variable names in df2).
I had heard of gt() and janitor(), but I never used either one. Thank you for the help.
You can see I added spanner labels. I had to use the columns option instead of spanners because I did not know how to handle that with the current headers having the same text for each variable. Perhaps you know a better way.
I was so accustomed to kableExtra, so I am glad to have a different option. Not sure why my original code would not work on the Mac, but would work on Windows, but you solved the problem with a more straight-forward approach.
I need to incorporate this into my workflow which includes a Quarto document that I use to produce a Word document. I am anxious to see how the table output looks in that format. I will let you know.
This is the table I ultimately wanted to make. It looked great in RStudio, but the rendered version in Word is shown in the screen shot below. You can format it (second screenshot), but that seems to defeat the purpose if that much work is required. The "<" is also still not presenting correctly.
I am not familiar enough with gt() so maybe this is all correctable. Do you have any ideas? Otherwise, I will study and may need to put in another post or go back to KableExtra with a windows computer. Thank you for getting me this far.
Hi @kbalkcom, thank you for the update.
I get similar dissappointing outputs when exporting to Word - either directly from the gt() object using as gt::as_word() or by embedding in a Quarto doc renders as Word format.
I had some success with gt::as_raw_html(); not perfect but passable maybe?
Thanks. I was able to produce the table output using your suggestion, but where markdown was used, the alignment in the row is off. (screenshot below). I thought the markdown code could be creating an error, so I tried html for the emphasis, but it did not recognize that. As a last resort, the markdown code can be removed and emphasis added manually in word.