只需尝试将列标题与其在knitr中的内容对齐。有什么作用?当我使用position = 'c'
或DF_3 <-structure(list(. = structure(c(11L, 6L, 7L, 8L, 13L, 5L, 4L, 2L, 12L, 3L, 1L, 10L, 9L),
.Label = c("B", "D", "E", "F", "G", "H", "H", "H", "I", "J", "M", "N", "V"), class = "f"),
HEV.pos = structure(c(3L, 8L, 1L, 6L, 2L, 9L, 8L, 10L, 7L, 3L, 8L, 4L, 5L),
.Label = c("1 (2)", "15", "16", "19", "20", "24", "26", "4 (7)", "6 (11)", "7 (13)"), class = "factor"),
HEV.neg = structure(c(9L, 2L, 7L, 1L, 6L, 1L, 7L, 10L, 5L, 4L, 8L, 3L, 5L),
.Label = c("10 (28)", "12 ", "15 ", "17", "18 ", "19 ", "2 ", "4", "7", "9"), class = "factor")),
class = "data.frame", row.names = c(NA, -13L))
library(knitr)
library(kableExtra)
library(dplyr)
kable(DF_3, format = "html") %>%
kable_styling(bootstrap_options = "striped") %>%
row_spec(1, bold = T) %>%
row_spec(6, bold = T) %>%
column_spec(1, bold = T)
时,它给我一个错误:
未使用的参数(align =“ c”)。
这是我的代码:
{{1}}
答案 0 :(得分:1)
不清楚您在哪里尝试使用align
参数。但是,必须将其提供给kable
函数。功能文档统计:
*列对齐:由“ l”(左),“ c”(中心)和/或“ r”(右)组成的字符向量。默认情况下,或者如果align = NULL,则数字列为右对齐,而其他列为左对齐。如果length(align)== 1L,则字符串将扩展为单个字母的向量,例如除非输出格式为LaTeX,否则'clc'变为c('c','l','c')。
例如:
knitr::kable(mtcars[1:5, 1:5], caption = "Left Aligned")
knitr::kable(mtcars[1:5, 1:5], align = "c", caption = "Center Aligned")
knitr::kable(mtcars[1:5, 1:5], align = c("c", "l", "r", "c", "c"), caption = "Mixed Aligned")