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

如何为formattable对象的行名称设置加粗格式?

Bold Row Names in formattable Object

Got it! To make the row names bold in your formattable output, you have a couple of straightforward ways to adjust your code. Here's how you can do it:

Method 1: Target row.names directly in the formatting list

This approach lets you define a specific formatter for row names while keeping your existing cell styling intact:

library(formattable)
formattable(mtcars, 
            align = "c", 
            list(
              # Add formatter for row names to make them bold
              row.names = formatter("span", style = ~ style(font.weight = "bold")),
              # Your original cell styling for all columns
              ~ formatter("span", style = x ~ formattable::style(display = "block", "border-radius" = "2px", "padding" = "5px", "text-align" = "center"))
            ))

Method 2: Use the row.names.style parameter (simpler)

If you just need basic bold styling for row names, you can use the built-in row.names.style parameter instead for a cleaner setup:

library(formattable)
formattable(mtcars, 
            align = "c", 
            # Set row names to bold directly
            row.names.style = style(font.weight = "bold"),
            # Your original cell styling
            list(
              ~ formatter("span", style = x ~ formattable::style(display = "block", "border-radius" = "2px", "padding" = "5px", "text-align" = "center"))
            ))

How it works

  • In Method 1, we add an entry row.names to the formatting list, using formatter("span") with font.weight = "bold" to apply bold styling specifically to row names. This gives you more flexibility if you want to add extra styling to row names later.
  • Method 2 uses the dedicated row.names.style parameter to apply the bold style concisely—perfect for simple, one-off styling needs.

Either way, your table's row names (like Mazda RX4, Mazda RX4 Wag, etc.) will now appear in bold, while your existing cell formatting stays exactly as you defined it.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.12 04:46:09