R 块输出在四开 PDF 中跨越一页以上的问题

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

R 块的输出超出了四开 PDF 中的单个页面,无法正确显示,如以下 R 代码输出所示。

如何正确渲染它?

---
book:
  title: "Title"
  author: "MYaseen208"
format:
  pdf:
    documentclass: scrreprt
    toc: true
    toc-depth: 3

execute:
  echo: false
  warning: false
---


# Experimental Planning & Layout

```{r}
library(knitr)
library(eda4treeR)
```

```{r}
#| label: Reading-Packages
#| output: false
```

## Example 2.1 (Pg. 22)

::: callout-tip
## Example 2.1 (Pg. 22)

A field trial was planted to compare a seedlot derived from a seed orchard (SO) with one collected from a routine population (P). There were eight plots of each seedlot, thinned at seven year of age. Tree diameters at breast height (dbh) were measured at 15 years and plot means calculated. An `R` program to carry out a Completely Randomized Analysis of plot means is given below:


```{r}
#| class-output: r
options(continue = " ", prompt   = " ")
example(
    topic          = "Exam2.1"
  , package        = "eda4treeR"
  , lib.loc        = NULL
  , character.only = c(TRUE, FALSE)[2]
  , give.lines     = c(TRUE, FALSE)[2]
  , local          = c(TRUE, FALSE)[2]
  , type           = c("console", "html")[2]
  , echo           = c(TRUE, FALSE)[1]
  , verbose        = getOption("verbose")
  , setRNG         = c(TRUE, FALSE)[1]
  , ask            = getOption("example.ask")
  , prompt.prefix  = NULL
  , run.dontrun    = c(TRUE, FALSE)[2]
  , run.donttest   = interactive()
  )
```
:::

## Example 2.2 (Pg. 24)

::: callout-tip
## Example 2.2 (Pg. 24)

A field trial was planted to compare a seedlot derived from a seed orchard (SO) with one collected from a routine population (P). There were eight plots of each seedlot, thinned at seven year of age. Tree diameters at breast height (dbh) were measured at 15 years and plot means calculated. An `R` program to carry out a Randomized Complete Block Analysis of plot means is given below:


```{r}
#| class-output: r
options(continue = " ", prompt   = " ")
example(
    topic          = "Exam2.2"
  , package        = "eda4treeR"
  , lib.loc        = NULL
  , character.only = c(TRUE, FALSE)[2]
  , give.lines     = c(TRUE, FALSE)[2]
  , local          = c(TRUE, FALSE)[2]
  , type           = c("console", "html")[2]
  , echo           = c(TRUE, FALSE)[1]
  , verbose        = getOption("verbose")
  , setRNG         = c(TRUE, FALSE)[1]
  , ask            = getOption("example.ask")
  , prompt.prefix  = NULL
  , run.dontrun    = c(TRUE, FALSE)[2]
  , run.donttest   = interactive()
  )
```

:::
r pdf latex knitr quarto
1个回答
1
投票

您可以设置 pdf 选项

listings: true
以便正确显示输出,但是,您需要应用一些额外的样式来镜像
class-output: r
的样式(请参阅此 post)。

---
format:
  pdf:
    documentclass: scrreprt
    toc: true
    toc-depth: 3
    listings: true
    include-in-header:
      - text: |
          \usepackage[usenames,dvipsnames]{color}    
          \lstset{ 
            language=R,                     % the language of the code
            basicstyle=\tiny\ttfamily, % the size of the fonts that are used for the code
            numbers=left,                   % where to put the line-numbers
            numberstyle=\tiny\color{Blue},  % the style that is used for the line-numbers
            stepnumber=1,                   % the step between two line-numbers. If it is 1, each line
                                            % will be numbered
            numbersep=5pt,                  % how far the line-numbers are from the code
            backgroundcolor=\color{white},  % choose the background color. You must add \usepackage{color}
            showspaces=false,               % show spaces adding particular underscores
            showstringspaces=false,         % underline spaces within strings
            showtabs=false,                 % show tabs within strings adding particular underscores
            frame=single,                   % adds a frame around the code
            rulecolor=\color{black},        % if not set, the frame-color may be changed on line-breaks within not-black text (e.g. commens (green here))
            tabsize=2,                      % sets default tabsize to 2 spaces
            captionpos=b,                   % sets the caption-position to bottom
            breaklines=true,                % sets automatic line breaking
            breakatwhitespace=false,        % sets if automatic breaks should only happen at whitespace
            keywordstyle=\color{RoyalBlue},      % keyword style
            commentstyle=\color{YellowGreen},   % comment style
            stringstyle=\color{ForestGreen}      % string literal style
          } 


execute:
  echo: false
  warning: false
---

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