0

I am new to xtable and R in general. I have a pdf document that I want to include a table with specified column widths. I tried playing with some formatting by reading what I can find online. However, I am unable to remove the rownames and hline after using the align function to set column widths.

ortho <- xtable(orthoInstructions, 
      include.rownames = FALSE, 
      hline.after = NULL)
align(ortho) <- c("p{0.1cm}","p{6cm}",
                "p{16cm}")
print(ortho)

structure(list(Name = c("Aspirin only", "Clopidogrel or other -grels only", 
"Dual Antiplatelet (Aspirin AND Clopidogrel or other -grels)", 
"NSAIDS for pain (e.g. ibuprofen, naproxen, diclofenac)"), PlanNormal = c("Stop 7 days before surgery", 
"Stop 3 to 7 days before surgery (PAC Nurse to advise)", "PAC Nurse to advise (Dual antiplatelets) - discuss with surgeon and anaesthetist", 
"Stop 2 days before surgery")), row.names = c(NA, -4L), class = c("tbl_df", 
"tbl", "data.frame"))

Have I missed something obvious?

Larry Li
  • 73
  • 6
  • They are arguments for `?xtable::print.xtable` not `xtable` – user20650 Nov 23 '19 at 12:59
  • Ah, so I should align first then use the `print.table` to generate the final table? – Larry Li Nov 23 '19 at 13:39
  • 1
    hi, this isn't really a solution to your problem but you might be interested in checking the ```stargazer``` package, which allows to customize LaTeX tables much more than ```xtable``` – bretauv Nov 23 '19 at 17:01
  • @bretauv what do you base this statement on? Isn't the **main** purpose of `stargazer` to easily and automatically generate model and summary statistics tables, while `xtable` is more general? Yes, `stargazer` is most likely the best for statistical/scientific work for the most common model classes. But in my opinion, `xtable` is much better suited for everything else, especially because it is so easy and straightforward to customize the LaTeX output. Please correct me if I'm wrong. I'd love to start using `startgazer` for more stuff than just beautiful model tables :) – henrik_ibsen Nov 24 '19 at 09:58
  • actually, there is an option ```summary = FALSE``` in ```stargazer``` that allows to generate the LaTeX code for a simple dataframe (if you set it as ```TRUE```, summary stats will be automatically computed). – bretauv Nov 24 '19 at 10:31
  • This has nothing to do with customization of a LaTeX table. This is simply forcing it to disable its main functionality and generate a default table. – henrik_ibsen Nov 24 '19 at 14:11
  • 1
    @LarryLi; yes. If the format is simple enough Id use `align` within the `xtable` function and then pass the further options to the print statment. So for your example, I'd do `print(xtable(orthoInstructions, align="lp{6cm}p{6cm}"), include.rownames = FALSE, hline.after = NULL)` – user20650 Nov 26 '19 at 00:04

0 Answers0