在使用 bookdown 创建的 pdf 文档中代码行太长

问题描述 投票:0回答:1

我正在尝试通过 RStudio 用 bookdown 来写我的论文,因为我对 Latex 不太熟悉。 我想在附录中添加为该项目生成的代码,但行不会中断,因此代码始终在页面上运行。

我在很长一段时间内尝试了太多,以至于我不再知道我尝试了什么或什么可能会干扰。我尝试更改代码块中的大小,但它没有执行任何操作(所以这里:

{r app, eval = FALSE, size = "tiny"} 

另一个想法是改变纸张的旋转,但我也无法做到,也许我写错了页?

如果有人能帮助我,我将非常感激。谢谢!

我的索引文件如下所示:

---
title: "Thesis"
site: "bookdown::bookdown_site"
documentclass: book
output:
bookdown::pdf_book:
keep_tex: true
extra_dependencies: ["float"]
citation_package: biblatex
toc: true
toc_depth: 3
includes:
in_header:
- \usepackage{pdfpages}
bibliography: [file.bib]
link-citations: yes
geometry: "left=4cm, right=3cm, top=2.5cm, bottom=2.5cm"
---

And the head of the appendix document with an example of code that ist way too long:
# Appendix: Codes {.unnumbered #appendix}
\markboth{APPENDIX}{}

## app.R {-}
```{r app, eval = FALSE} 
  # Inputs ------------------------------------------------------------------

  ## Transform excel input data
  input_data <- reactive({
    req(input$file)
    
    # functions used here are generated in 02_functions.r
    headers  <- read_excel(input$file$datapath, col_names = FALSE, n_max = 2) %>% tibble::as_tibble() %>% mutate(...3 = NA)
    data     <- read_excel(input$file$datapath, col_names = FALSE, skip = 2)  %>% tibble::as_tibble()
    return(data)
  })

```

这会导致这样的事情:

enter image description here

我尝试过:

  • 更改代码块选项中的代码大小
  • 更改页面的旋转
  • 使用 \usepackage{fvextra}
  • 使用 \DefineVerbatimEnvironment{突出显示}{Verbatim}{breaklines,commandchars=\{}}
  • 在index.Rmd的in_header部分使用\lstset{breaklines=true}
  • 使用额外的 tex 文件 %\usepackage{fvextra} %\DefineVerbatimEnvironment{突出显示}{Verbatim}{breaklines,commandchars=\{}}
rstudio line-breaks bookdown pdflatex
1个回答
0
投票
---
title: "Thesis"
site: "bookdown::bookdown_site"
documentclass: book
output:
  bookdown::pdf_book:
    keep_tex: true
extra_dependencies: ["float"]
citation_package: biblatex
toc: true
toc_depth: 3
header-includes:
- \usepackage{pdfpages}
- \usepackage{fvextra}
- \DefineVerbatimEnvironment{Highlighting}{Verbatim}{commandchars=\\\{\},breaklines=true, breakanywhere=true}
link-citations: yes
geometry: "left=4cm, right=3cm, top=2.5cm, bottom=2.5cm"
---

And the head of the appendix document with an example of code that ist way too long:
# Appendix: Codes {.unnumbered #appendix}
\markboth{APPENDIX}{}

## app.R {-}
```{r app, eval = FALSE} 
  # Inputs ------------------------------------------------------------------

  ## Transform excel input data
  input_data <- reactive({
    req(input$file)
    
    # functions used here are generated in 02_functions.r
    headers  <- read_excel(input$file$datapath, col_names = FALSE, n_max = 2) %>% tibble::as_tibble() %>% mutate(...3 = NA)
    data     <- read_excel(input$file$datapath, col_names = FALSE, skip = 2)  %>% tibble::as_tibble()
    return(data)
  })

```

© www.soinside.com 2019 - 2024. All rights reserved.