Gt: Table.width = pct(100) ignored in pdf

Created on 23 Jul 2019  Â·  11Comments  Â·  Source: rstudio/gt

hi,

Setting the tab_options(table.width = pct(100)) does not seem to have the desired effect when creating pdfs.

title: "Test"
output: pdf_document
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)

```{r pressure, echo=FALSE}
library(gt)
library(tidyverse)
library(glue)

Define the start and end dates for the data range

start_date <- "2010-06-07"
end_date <- "2010-06-14"

Create a gt table based on preprocessed

sp500 table data

sp500 %>%
dplyr::filter(date >= start_date & date <= end_date) %>%
dplyr::select(-adj_close) %>%
gt() %>%
tab_header(
title = "S&P 500",
subtitle = glue::glue("{start_date} to {end_date}")
) %>%
fmt_date(
columns = vars(date),
date_style = 3
) %>%
fmt_currency(
columns = vars(open, high, low, close),
currency = "USD"
) %>%
fmt_number(
columns = vars(volume),
suffixing = TRUE
) %>% tab_options(
table.width = pct(100)
)


[2] Intermediate [2] Medium [2] Medium ★ Enhancement

Most helpful comment

@rich-iannone Thanks so much,

tab_options(row.striping.include_table_body = FALSE) is working, my dark shade disappeared..
Thanks a ton... 🥇

All 11 comments

Thanks for filing this issue. We do have quite a few things not yet implemented in anything other than HTML. We will get to those! We just need to make sure everything is solid for HTML, then we’ll make sure things like this work in LaTeX and RTF.

Hello @rich-iannone I face the same issue in html with tab_options I could do row_padding, but when it comes to table.width = pct(100), I get a horizontal scroll bar, I want to display my entire table having 8 rows and 7 columns .

data_frm_tbl %>%
gt() %>%
tab_header(
title = "Total tested and total tested diabetic",
subtitle = glue::glue("Patient Count")
) %>%
cols_width(
starts_with("n") ~ px(175),
starts_with("H") ~ px(175),
starts_with("d") ~ px(145),
starts_with("t") ~ px(120),
TRUE ~ px(80)
) %>%
tab_options(
table.width = pct(100),
row.padding = px(3)
)
```
Please help me if I am making any mistake. Thank you.

And @rich-iannone when I render table using gt why is my table having a darker shade for every alternate row , how can I remove the dark shade, so that it looks like perfect clean table with uniform shade in every row. Thanks. Please give me suggestions asap. Thanks for your work with gt its great.

@krhemanth To turn the row striping off, we can use an option in tab_options():

exibble %>%
  gt() %>%
  tab_options(row.striping.include_table_body = FALSE)

In a later update, having unstriped rows will be the default (requiring the use of a function or tab_options() to enable). But, for now, this is the only way to disable them.

@rich-iannone Thanks so much for your response, But I dint find any changes from using [tab_options(row.striping.include_table_body = FALSE)] I still get scroll bar , so I increased my Rmarkdown default width, so now I get my complete table,

And Now how can I remove the dark shade appearing in every alternate row, by default. This does not make the output look like a normal table. Thanks once again.

The above code example (with tab_options()) should make the row shading disappear. Do you have the latest version of gt on master? Could you please install the latest using remotes::install_github("rstudio/gt") and try once more?

@rich-iannone when I try to install gt using the above command I get this error

remotes::install_github("rstudio/gt")
Error: Failed to install 'gt' from GitHub:
Timeout was reached: [api.github.com] Connection timed out after 10000 milliseconds

I use R 3.6.1 and I am not sure how to check my gt version, every time I run the code I load the package from.

pkglist <- c('dplyr', 'tsibble' ,'lubridate', 'stringr',
'mice', 'tidyr', 'data.table', 'summarytools',
'gt', 'kableExtra', 'knitr', 'xtable',
'ggplot2', 'stats', 'ggpubr', 'gganimate',
'ggrepel', 'zipcode' ,'noncensus',
'htmltools')

check.and.install.Package<-function(package_name){
if (!package_name %in% installed.packages()) {
install.packages(package_name, repos='http://cran.us.r-project.org')
}
}

and I am using proxy server in my office will this be an problem for
" remotes::install_github("rstudio/gt") " not working.

@rich-iannone Thanks so much,

tab_options(row.striping.include_table_body = FALSE) is working, my dark shade disappeared..
Thanks a ton... 🥇

@rich-iannone , Thanks for continuous support for my every question, I have come up with a new question, How can I create a border to the table generated using gt, example a vertical line in the left side and right side of the table so that it looks like a border for the entire table. Thank you.

Hello @rich-iannone ,

any leads for creating borders. in the all the four corners of the table,

Was this page helpful?
0 / 5 - 0 ratings