You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

在RMarkdown的kable中设置列名空白及行名上标

Solution for Kable Table Adjustments in RMarkdown
  • Set the row names column header to blank:
    When generating the table with kable, use the col.names parameter to replace the default row names header with an empty string. Since the row names column becomes the first column when row.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 ^1 for LaTeX output or <sup>1</sup> for HTML). Then set escape = FALSE in kable to 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 ^1 with <sup>1</sup> to get proper superscript formatting.

内容的提问来源于stack exchange,提问作者Maria

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.04 06:33:16