adding rows or boldify single row.names with print.xtables – add something in between rows?

前端 未结 1 660
感情败类
感情败类 2021-01-13 03:40

I try to use print.xtable add.to.row to get table formatted like this:

sports

share of ballers    22.3 
sh         


        
相关标签:
1条回答
  • 2021-01-13 03:52

    For the hline part, see ?print.xtable.

    hline.after: When 'type="latex"', a vector of numbers between -1 and '"nrow(x)"', inclusive, indicating the rows after which a horizontal line should appear

    To embolden all you rows names:

    bold.allrows <- function(x) {
      h <- paste('\\textbf{',x,'}', sep ='')
      h
    }
    print(xtable(yourTable), 
          sanitize.rownames.function =  bold.allrows)
    

    To embolden some row names, you can add a " special markup" to those rows, e.g. BOLD:

    bold.somerows <- 
            function(x) gsub('BOLD(.*)',paste('\\\\textbf{\\1','}'),x)
    
    print(xtable(yourTable), 
          sanitize.rownames.function =  bold.somerows)
    

    e.g:

    require(xtable)
    hh <- head(mtcars)[ , c(1:5)]
    ## I want to bold 1 and 3 rows 
    rownames(hh)[c(1, 3)] <- paste('BOLD', rownames(hh)[c(1, 3)])
    print(xtable(hh), sanitize.rownames.function =  bold.somerows)
    
    0 讨论(0)
提交回复
热议问题