Reputation: 43
My goal is to generate a numeric bibliography in pdf using Rmarkdown and a .csl. However, no matter which .csl file I use, the first word of the references are all slightly misaligned from each other. I suspect it has something to do with how latex justifies but I don't know it or pandoc well enough to figure it out or fix it. Ideally I'm looking for a way to fix it in Rmarkdown. As far as I can tell this doesn't happen with non-numeric styles.
MRE:
First get some numeric .csl files, as far as I can tell it happens with any of them. https://www.zotero.org/styles is a good source, good examples are Nature (nature.csl), Science (science.csl), or Biomed Central (biomed-central.csl).
Then run this to generate a sample bib:
knitr::write_bib(c("knitr", "stringr", "ggplot2"), "test.bib")
Then knit this Rmd file:
---
title: "test"
output: pdf_document
bibliography: test.bib
csl: biomed-central.csl # whatever numeric .csl
---
# Citations
@R-ggplot2 @R-knitr @R-stringr @ggplot22016 @knitr2015 @knitr2014
# References
Results:
With biomed-central.csl:
With nature.csl (slight but still there):
With science.csl:
I have also tried different latex engines to no avail.
sessioninfo:
R version 3.6.2 (2019-12-12)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 18362)
Matrix products: default
locale:
[1] LC_COLLATE=English_United States.1252 LC_CTYPE=English_United States.1252 LC_MONETARY=English_United States.1252 LC_NUMERIC=C
[5] LC_TIME=English_United States.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] forcats_0.4.0 stringr_1.4.0 dplyr_0.8.3 purrr_0.3.3 readr_1.3.1 tidyr_1.0.0 tibble_2.1.3 ggplot2_3.2.1 tidyverse_1.3.0 rmarkdown_2.1.1
[11] knitr_1.27 here_0.1
loaded via a namespace (and not attached):
[1] tinytex_0.19 tidyselect_0.2.5 xfun_0.12 haven_2.2.0 lattice_0.20-38 colorspace_1.4-1 generics_0.0.2 vctrs_0.2.1 htmltools_0.4.0 yaml_2.2.0
[11] rlang_0.4.2 pillar_1.4.3 withr_2.1.2 glue_1.3.1 DBI_1.1.0 dbplyr_1.4.2 modelr_0.1.5 readxl_1.3.1 lifecycle_0.1.0 cellranger_1.1.0
[21] munsell_0.5.0 gtable_0.3.0 rvest_0.3.5 evaluate_0.14 labeling_0.3 fansi_0.4.1 highr_0.8 broom_0.5.3 Rcpp_1.0.3 scales_1.1.0
[31] backports_1.1.5 jsonlite_1.6 farver_2.0.3 fs_1.3.1 hms_0.5.3 digest_0.6.23 stringi_1.4.4 grid_3.6.2 rprojroot_1.3-2 cli_2.0.1
[41] tools_3.6.2 magrittr_1.5 lazyeval_0.2.2 crayon_1.3.4 pkgconfig_2.0.3 zeallot_0.1.0 ellipsis_0.3.0 xml2_1.2.2 reprex_0.3.0 lubridate_1.7.4
[51] assertthat_0.2.1 httr_1.4.1 rstudioapi_0.10 R6_2.4.1 nlme_3.1-142 compiler_3.6.2
Upvotes: 1
Views: 193
Reputation: 43
\raggedright
fixes the problem:
---
title: "test"
output: pdf_document
bibliography: test.bib
csl: biomed-central.csl # whatever numeric .csl
---
# Citations
@R-ggplot2 @R-knitr @R-stringr @ggplot22016 @knitr2015 @knitr2014
\raggedright
# References
Upvotes: 0