Search code examples
rlatexr-markdownbeamerbibtex

Remove blank page for beamer using natbib in Rmarkdown


My little example (test.rmd) is as follows:

---
output: 
  beamer_presentation:
    latex_engine: xelatex
    citation_package: natbib
bibliography: ref.bib
biblio-style: "unsrtnat" 
colorlinks: yes
---

## Papers

- Cp @mallows1973some
- AIC @akaike1974new
- BIC @schwarz1978estimating
- GCV @craven1978smoothing
- bridge @frank1993statistical
- LASSO @tibshirani1996regression
- SCAD @fan2001variable
- MCP @zhang2010nearly

## References {.allowframebreaks}

where ref.bib is

@Article{mallows1973some,
  author  = {Mallows, Colin L.},
  journal = {Technometrics},
  title   = {{Some comments on $C_p$}},
  year    = {1973},
  number  = {1},
  pages   = {87--94},
  volume  = {42},
}

@Article{akaike1974new,
  author  = {Akaike, Hirotugu},
  journal = {IEEE Transactions on Automatic Control},
  title   = {A new look at the statistical model identification},
  year    = {1974},
  number  = {6},
  pages   = {716--723},
  volume  = {19},
}

@Article{schwarz1978estimating,
  author    = {Schwarz, Gideon},
  journal   = {The Annals of Statistics},
  title     = {Estimating the dimension of a model},
  year      = {1978},
  number    = {2},
  pages     = {461--464},
  volume    = {6},
  publisher = {Institute of Mathematical Statistics},
}

@Article{craven1978smoothing,
  author  = {Craven, Peter and Wahba, Grace},
  journal = {Numerische Mathematik},
  title   = {Smoothing noisy data with spline functions},
  year    = {1978},
  number  = {4},
  pages   = {377--403},
  volume  = {31},
}

@Article{frank1993statistical,
  author  = {Frank, Ildiko E. and Friedman, Jerome H.},
  journal = {Technometrics},
  title   = {A statistical view of some chemometrics regression tools},
  year    = {1993},
  number  = {2},
  pages   = {109--135},
  volume  = {35},
}

@Article{tibshirani1996regression,
  author    = {Tibshirani, Robert},
  title     = {Regression shrinkage and selection via the lasso},
  journal   = {Journal of the Royal Statistical Society. Series B (Methodological)},
  year      = {1996},
  volume    = {58},
  number    = {1},
  pages     = {267--288},
  publisher = {JSTOR},
}

@Article{fan2001variable,
  author  = {Fan, Jianqing and Li, Runze},
  journal = {Journal of the American Statistical Association},
  title   = {Variable selection via nonconcave penalized likelihood and its oracle properties},
  year    = {2001},
  number  = {456},
  pages   = {1348--1360},
  volume  = {96},
}

@Article{zhang2010nearly,
  author  = {Zhang, Cun-Hui},
  journal = {The Annals of Statistics},
  title   = {Nearly unbiased variable selection under minimax concave penalty},
  year    = {2010},
  number  = {2},
  pages   = {894--942},
  volume  = {38},
}

My problem is that test.rmd can run successfully while there is a blank page in the second page.

One may suggest that I can use the csl: xxx.csl instead of citation_package: natbib in Rmarkdown for beamer. Surely, csl: xxx.csl is fine and can run without accidents, but I still prefer to using citation_package: natbib.

Curiously, if I change ## References {.allowframebreaks} in test.rmd with

`r if (knitr::is_html_output()) '
## References {.allowframebreaks}
'`

then the blank page disappears. However, a new problem has emerged; the frame title and the bookmark of References both disappear. How can I fix the problems?


Solution

  • Quick hack:

    ---
    output: 
      beamer_presentation:
        latex_engine: xelatex
        keep_tex: true
        citation_package: natbib
    bibliography: ref.bib
    biblio-style: "unsrtnat" 
    colorlinks: yes
    header-includes:
      - \pretocmd{\bibliographytrue}{\frametitle{References}}{}{}
    ---
    
    ## Papers
    
    - Cp @mallows1973some
    - AIC @akaike1974new
    - BIC @schwarz1978estimating
    - GCV @craven1978smoothing
    - bridge @frank1993statistical
    - LASSO @tibshirani1996regression
    - SCAD @fan2001variable
    - MCP @zhang2010nearly
    

    enter image description here