Search code examples
rlatexxtable

How to print xtable without hlines


assume I have a simply xtable, made as follows:

library(xtable)
x <- as.data.frame(matrix(1:9,3,3))
x <- xtable(x)

How can I print this table with only the columns (i.e. '&'s), but not anything around? I do not want hlines explicitly.

Using:

print(x,
only.contents=T)

returns \hline before and after the table. I'd be also happy with a workaround, even though I hope it is possible somehow within xtable to set this up as intended. Thanks for any hints.


Solution

  • You can set hline.after to NULL; see below:

    library(xtable)
    x <- as.data.frame(matrix(1:9,3,3))
    
    print(xtable(x),
          only.contents=T)
    
    #> % latex table generated in R 3.6.0 by xtable 1.8-4 package
    #> % Wed Sep 18 11:54:58 2019
    #>  & V1 & V2 & V3 \\ 
    #>   \hline
    #> 1 &   1 &   4 &   7 \\ 
    #>   2 &   2 &   5 &   8 \\ 
    #>   3 &   3 &   6 &   9 \\ 
    #>    \hline
    
    print(xtable(x),
          hline.after = NULL,
          only.contents=T)
    
    #> % latex table generated in R 3.6.0 by xtable 1.8-4 package
    #> % Wed Sep 18 11:54:58 2019
    #>  & V1 & V2 & V3 \\ 
    #>  1 &   1 &   4 &   7 \\ 
    #>   2 &   2 &   5 &   8 \\ 
    #>   3 &   3 &   6 &   9 \\ 
    #> 
    

    You can read more in ?print.xtable.