在RMarkdown的kable中设置列名空白及行名上标
Solution for Kable Table Adjustments in RMarkdown
Set the row names column header to blank:
When generating the table withkable, use thecol.namesparameter to replace the default row names header with an empty string. Since the row names column becomes the first column whenrow.names = TRUE, pass a vector starting with""followed by your data frame's column names.Modify the 7th row name with superscript:
Update the 7th row name of your data frame to include the superscript syntax (use^1for LaTeX output or<sup>1</sup>for HTML). Then setescape = FALSEinkableto ensure the superscript renders correctly instead of being treated as plain text.
Example Code
Assuming your data frame is named my_df:
# Modify the 7th row name (use <sup>1</sup> if outputting to HTML) rownames(my_df)[7] <- "Demanda interna^1" # Generate the table with blank row header and rendered superscript library(knitr) kable(my_df, row.names = TRUE, col.names = c("", names(my_df)), # Blank first column header escape = FALSE) # Allow superscript syntax
Notes
- If you don’t want to modify the original data frame, create a copy first:
my_df_temp <- my_df rownames(my_df_temp)[7] <- "Demanda interna^1" kable(my_df_temp, row.names = TRUE, col.names = c("", names(my_df_temp)), escape = FALSE) - For HTML output, replace
^1with<sup>1</sup>to get proper superscript formatting.
内容的提问来源于stack exchange,提问作者Maria
相关产品推荐
相关产品推荐

