harrelfe / Hmisc

Harrell Miscellaneous
Other
208 stars 81 forks source link

\cline{} across too many columns when dropping rownames #71

Closed nielsaka closed 6 years ago

nielsaka commented 7 years ago

I encounter an unwanted behaviour when I turn off the use of rownames and define a group of columns at the same time. More specifically, when I specify rownames = NULL in combination with cgroup and n.cgroup in the call to latex(), the resulting horizontal \cline will span all the available columns, even though the column grouping might only refer to a subset of columns.

An example

df <- data.frame(A = 1:3, B = 4:6, C = 7:9)

# Will print \cline{4-5}. Looks perfect.
latex(df, file = "",
      cgroup = c("", "B and C"),
      n.cgroup = c(1, 2))

# Will print \cline{1-4}. The horizontal line is too long.
latex(df, file = "",
      cgroup = c("", "B and C"),
      n.cgroup = c(1, 2),
      rowname = NULL)

The relevant code is here, where the cline object only gets formatted if rownames is of length greater than one, i.e. not NULL.

nielsaka commented 7 years ago

I found a quick workaround using rowlabel = "" , rowname = "". This will stop the printing of rownames, while keeping the \cline intact. The only downside are whitespaces on the very left of the table, which make it look slightly asymmetrical.