Note that there are some explanatory texts on larger screens.

plurals
  1. POMisaligned columns in HTML tables using hwriter/xtable
    text
    copied!<p>I have been trying to convert a list into HTML table, using both xtable and hwriter R packages. Here is how the list looks like:</p> <pre><code>structure(list(sex = structure(list(`study 1` = structure(c(2L, 1L), .Label = c("111 (55.5%)", "89 (44.5%)"), class = "factor"), `study 2` = structure(1:2, .Label = c("29 (30.21%)", "67 (69.79%)" ), class = "factor"), `study 3` = structure(c(2L, 1L), .Label = c("112 (56.85%)", "85 (43.15%)"), class = "factor"), `study 113220` = structure(1:2, .Label = c("132 (44.75%)", "163 (55.25%)"), class = "factor")), .Names = c("study 1", "study 2", "study 3", "study 113220"), class = "data.frame", row.names = c("0", "1")), ethnic = structure(list(`study 1` = structure(c(2L, 1L ), .Label = c("194 (97%)", "6 (3%)"), class = "factor"), `study 2` = structure(1:2, .Label = c("2 (2.08%)", "94 (97.92%)"), class = "factor"), `study 3` = structure(c(2L,1L), .Label = c("194 (98.48%)", "3 (1.52%)"), class = "factor"), `study 113220` = structure(1:2, .Label = c("10 (3.39%)", "285 (96.61%)"), class = "factor")), .Names = c("study 1", "study 2", "study 3", "study 113220"), class = "data.frame", row.names = c("1", "2")), race = structure(list(`study 1` = structure(c(4L, 1L, 1L, 3L, 3L, 2L, NA, NA, NA, NA), .Label = c("1 (0.5%)", "187 (93.5%)", "2 (1%)", "7 (3.5%)"), class = "factor"), `study 2` = structure(c(NA, NA, NA, NA, 1L, 2L, NA, NA, NA, NA), .Label = c("1 (1.04%)", "95 (98.96%)"), class = "factor"), `study 3` = structure(c(NA, NA, NA, NA, 2L, 1L, NA, NA, NA, NA), .Label = c("195 (98.98%)", "2 (1.02%)"), class = "factor"), `study 113220` = structure(c(1L, NA, 1L, NA, NA, 2L, 1L, 1L, 1L, 1L), .Label = c("1 (0.34%)", "289 (97.97%)"), class = "factor")), .Names = c("study 1", "study 2", "study 3", "study 113220"), class = "data.frame", row.names = c("11", "14", "15", "17", "18", "19", "13", "16", "99", "NA"))), .Names = c("sex", "ethnic", "race")) </code></pre> <p>And here is how I create the HTML table I have come up with:</p> <pre><code>writeHTML = function(list,file){ widthpx = sprintf("%d",100*(1+ncol(list[[1]]))) vect = sapply(1:length(x), function(i) hwrite(list[[i]], center=T, table.style="border-collapse:collapse", table.frame="void", table.rules="all", border=1, row.names=T, cellpadding="5px", row.style=list("font-weight:bold"), width=widthpx, col.width="70px") ) names(vect) = names(list) hwrite(vect, page=file, center=T, table.style="border-collapse:collapse", border=4, row.names=T, col.style=list("font-weight:bold"), dim=c(length(vect),1)) } writeHTML(x,"x.html") </code></pre> <p>but the columns are misaligned....</p> <p>Anyone has any idea how to fix this? Thanks!!!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload