bookdown将章节转换为章节

时间:2018-03-09 17:02:47

标签: r latex bookdown

我有一本书可以很好地编译成html,但pdf版本没有章节。例如,命令

# Introduction {#intro-intro}

被翻译为

\hypertarget{intro-intro}{%
\section{Introduction}\label{intro-intro}}

(gitbook格式没有这样的问题)

<EDIT>

# Preface {-}顶部有Index.Rmd,最后有\mainmatter。也许它没有脱离前言?罗马数字在# Introduction处变回非罗马数字。

</EDIT>

我的Index.Rmd

---
documentclass: krantz
classoption: numberinsequence
bibliography: [book.bib]
biblio-style: apalike
link-citations: yes
colorlinks: yes
graphics: yes
---

_bookdown.yml

new_session: yes    
output_dir: working_files
clean: [bookdown.bbl]
language:
  label:
    fig: "Fig. "
    tab: "Table "

_output.yml

  bookdown::gitbook:
    css: css/style.css
    dev: svglite

  bookdown::pdf_book:
    includes:
      in_header: latex_extras/preamble.tex
      before_body: latex_extras/before_body.tex
      after_body: latex_extras/after_body.tex
    keep_tex: yes
    dev: "cairo_pdf"
    latex_engine: pdflatex
    citation_package: natbib
    template: null
    toc_unnumbered: no
    toc_appendix: yes
    quote_footer: ["\\VA{", "}{}"]

最后

  > session_info()
  ─ Session info ───────────────────────────────────────────────────────────────
  setting  value                       
  version  R version 3.4.3 (2017-11-30)
  os       macOS High Sierra 10.13.3   
  system   x86_64, darwin15.6.0        
  ui       X11                         
  language (EN)                        
  collate  en_US.UTF-8                 
  tz       America/New_York            
  date     2018-03-09                  

  ─ Packages ───────────────────────────────────────────────────────────────────
  package     * version date       source         
  backports     1.1.2   2017-12-13 CRAN (R 3.4.3) 
  bookdown    * 0.7     2018-02-18 CRAN (R 3.4.3) 
  clisymbols    1.2.0   2017-05-21 CRAN (R 3.4.0) 
  digest        0.6.15  2018-01-28 cran (@0.6.15) 
  evaluate      0.10.1  2017-06-24 CRAN (R 3.4.1) 
  htmltools     0.3.6   2017-04-28 CRAN (R 3.4.0) 
  knitr         1.20    2018-02-20 CRAN (R 3.4.3) 
  magrittr      1.5     2014-11-22 CRAN (R 3.4.0) 
  Rcpp          0.12.15 2018-01-20 cran (@0.12.15)
  rmarkdown   * 1.8     2017-11-17 CRAN (R 3.4.2) 
  rprojroot     1.3-2   2018-01-03 cran (@1.3-2)  
  sessioninfo * 1.0.0   2017-06-21 CRAN (R 3.4.1) 
  stringi       1.1.6   2017-11-17 CRAN (R 3.4.2) 
  stringr       1.3.0   2018-02-19 CRAN (R 3.4.3) 
  withr         2.1.1   2017-12-19 CRAN (R 3.4.3) 
  xfun          0.1     2018-01-22 cran (@0.1)    

1 个答案:

答案 0 :(得分:0)

Pandoc默认情况下会将#转换为\section{}(严格来说不是真的,但请参阅Pandoc's manual了解详细信息)。要让它知道你想要章节,你必须使用参数--top-level-divisionexample here)。