Skip to content

Commit

Permalink
Merge pull request #168 from tidy-survey-r/copyedit-latex-edits
Browse files Browse the repository at this point in the history
Use both table and longtable in LaTeX
  • Loading branch information
ivelasq authored Aug 22, 2024
2 parents 27a43d4 + db9ba46 commit ec349b6
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 8 deletions.
2 changes: 1 addition & 1 deletion 05-descriptive-analysis.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@ recs_des %>%
mutate(p = p * 100)
```

with `r .preg %>% filter(Region=="Northeast") %>% pull(p) %>% signif(3)`% of the households in the Northeast, `r .preg %>% filter(Region=="Midwest") %>% pull(p) %>% signif(3)`% in the Midwest, and so on. Note that the proportions in column `p` add up to one.
`r .preg %>% filter(Region=="Northeast") %>% pull(p) %>% signif(3)`% of the households are in the Northeast, `r .preg %>% filter(Region=="Midwest") %>% pull(p) %>% signif(3)`% are in the Midwest, and so on. Note that the proportions in column `p` add up to one.

\index{Categorical data|(}
The `survey_prop()` function is essentially the same as using `survey_mean()` with a categorical variable and without specifying a numeric variable in the `x` argument. The following code gives us the same results as above:
Expand Down
12 changes: 9 additions & 3 deletions index.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ header-includes:
```{r setup}
#| include: false
knitr::opts_chunk$set(fig.pos = "h!", out.extra = "")
library(styler)
options(
htmltools.dir.version = FALSE, formatR.indent = 2, digits = 4
Expand All @@ -38,9 +40,13 @@ library(prettyunits)
book_colors <- c("#0b3954", "#087e8b", "#bfd7ea", "#ff8484", "#8d6b94")
as_latex_with_caption <- function(gtobj, chunk_label) {
gt_l <- gt::as_latex(gtobj)
lt <- nrow(gtobj[["_data"]]) >= 10
gt_l <- gtobj %>% tab_options(latex.use_longtable=lt, latex.tbl.pos="!htb") %>% gt::as_latex()
caption <- paste0(
"\\caption{\\label{tab:", chunk_label, "}(ref:", chunk_label, ")}\\\\")
"\\caption{\\label{tab:", chunk_label, "}(ref:", chunk_label, ")}")
if (lt){
caption <- paste0(caption, " \\\\")
}
latex <- strsplit(gt_l[1], split = "\n")[[1]]
idxtable <- which(stringr::str_detect(latex, "begin") & stringr::str_detect(latex, "table"))
# https://tex.stackexchange.com/questions/95236/as-first-character-in-table-row
Expand Down Expand Up @@ -139,4 +145,4 @@ if (knitr:::is_html_output()){
}
rm(citation_text)
```
```
14 changes: 10 additions & 4 deletions renv.lock
Original file line number Diff line number Diff line change
Expand Up @@ -956,9 +956,15 @@
},
"gt": {
"Package": "gt",
"Version": "0.10.1",
"Source": "Repository",
"Repository": "CRAN",
"Version": "0.11.0.9000",
"Source": "GitHub",
"RemoteType": "github",
"RemoteHost": "api.github.com",
"RemoteRepo": "gt",
"RemoteUsername": "rstudio",
"RemotePkgRef": "rstudio/gt",
"RemoteRef": "HEAD",
"RemoteSha": "28de628ac53ecded0f747396333507477f537923",
"Requirements": [
"R",
"base64enc",
Expand All @@ -982,7 +988,7 @@
"vctrs",
"xml2"
],
"Hash": "03009c105dfae79460b8eb9d8cf791e4"
"Hash": "f6b5b788ea3cdec44401645c5896ad8c"
},
"gtable": {
"Package": "gtable",
Expand Down

0 comments on commit ec349b6

Please sign in to comment.