nutterb / pixiedust

Tables So Beautifully Fine-Tuned You Will Believe It's Magic.
179 stars 18 forks source link

Table header in LaTex #69

Closed lepennec closed 7 years ago

lepennec commented 7 years ago

Hi,

I'm playing with your package and the default for a table with LaTex seems very different from the default in HTM: the header is not separated from the rest by an horizontal line and the table itself does not have a top and bottom line. I have been able to add the first horizontal line with sprinkle(part = "head", border = c("bottom"), border_color = "black" but did not find a way to add the two other lines (other than adding a top line for the header and a bottom line for the last line which is not very satisfactory...)

Erwan

nutterb commented 7 years ago

It's hard to know what you're seeing, but for illustration, this is the HTML table I get using the pure defaults

library(pixiedust)

fit <- lm(mpg ~ wt + qsec + am, data = mtcars)

dust(fit,
     caption = "Linear Model")

image

The LaTeX table is a very little bit different

image

Because I think the presentation you are referring to is somewhat common, pixiedust has a standard medley function that can add these lines. The code for it is

library(pixiedust)

fit <- lm(mpg ~ wt + qsec + am, data = mtcars)

dust(fit,
     caption = "Linear Model") %>%
  medley_bw()

image

And the PDF output is

image

Note: my YAML content for the PDF output included

---
title: "Examples"
output: pdf_document
header-includes: 
- \usepackage{amssymb} 
- \usepackage{arydshln} 
- \usepackage{caption} 
- \usepackage{graphicx} 
- \usepackage{hhline} 
- \usepackage{longtable} 
- \usepackage{multirow} 
- \usepackage[dvipsnames,table]{xcolor} 
---

If you are getting different HTML output than I am, it's possible you have a CSS file loaded that is influencing your table layout (pixiedust won't override CSS settings unless explicitly instructed to do so). Does that help get the presentation you want?

lepennec commented 7 years ago

Thank you for your help. My mistake was coming from the fact that in the vignette there was a

library(pixiedust)
dust(fit)

which produces a table with some borders. Looking at the source, it seems that this indeed due to some (defaullt?) CSS setting in the vignette...

nutterb commented 7 years ago

Oh, I've never noticed that. I will look further into it, because I can see why that would be confusing.

Thanks for pointing it out.

lepennec commented 7 years ago

It is indeed a default CSS setting for the vignettes.. but as stated in the vignette vignette:

You can use your own CSS file instead of the built-in style in the markdown package – just set the option markdown.HTML.stylesheet, e.g. options(markdown.HTML.stylesheet = "path/to/a/custom/style.css")

nutterb commented 7 years ago

There's also the option to use

output: 
  rmarkdown::html_vignette:
    css: mystyles.css

(see: http://rmarkdown.rstudio.com/package_vignette_format.html)

The actual CSS for html_vignette

For pixiedust, using a blank CSS file would be optimal.

nutterb commented 7 years ago

A css file has been added to the templates. The vignettes will be corrected in the next release. Thanks.