如何在四开 PDF 文档中将 R 代码和输出移动到右侧?

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

我想将

R
代码及其输出移至四开渲染 PDF 文档的右侧。你能帮我实现这个目标吗?以下是我正在使用的
YAML
标头:

---
title: |
  \huge \textbf{Title}
format: 
  pdf:
    fig-width: 4
    fig-height: 3
    fig-align: center
    out.width: '100%'
    fig-format: pdf
    include-in-header: 
      text: |
        \usepackage[none]{hyphenat}
        \usepackage{enumitem}
        \setlist[enumerate]{font=\bfseries}
        \usepackage{float}
        \usepackage{scrlayer-scrpage}
        \usepackage[a4paper,
            bindingoffset=0.2in,
            left=0.5in,
            right=0.5in,
            top=0.85in,
            bottom=0.85in,
            footskip=0.5in]{geometry} 
        \usepackage{titling}
        \setlength{\droptitle}{-2cm}
        \clearpairofpagestyles
        \lohead*{\textbf{Stat-8010}}
        \cohead*{\textbf{Statistical Methods I}}
        \rohead*{\textbf{Spring 2025}}
        \cofoot*{\pagemark}
        
        \usepackage{etoolbox}
        \AtBeginEnvironment{verbatim}{\setlength{\leftskip}{5cm}} % Adjust left margin for verbatim
        \AtBeginEnvironment{knitrout}{\setlength{\leftskip}{2cm}} % Adjust left margin for knitrout
execute:
  warning: false
  message: false
  error: false
  echo: true
---

# Intro
1.  This is a simple use of quarto.

```{r}
1 + 1
```
r pdf yaml knitr quarto
1个回答
0
投票

这是因为你的缩进不正确。我假设“向右移动”是指代码的缩进和右侧的输出。 元素应与列表的第一个字符对齐。 以下将正常工作:

---
title: |
  \huge \textbf{Title}
format: 
  pdf:
    fig-width: 4
    fig-height: 3
    fig-align: center
    out.width: '100%'
    fig-format: pdf
    include-in-header: 
      text: |
        \usepackage[none]{hyphenat}
        \usepackage{enumitem}
        \setlist[enumerate]{font=\bfseries}
        \usepackage{float}
        \usepackage{scrlayer-scrpage}
        \usepackage[a4paper,
            bindingoffset=0.2in,
            left=0.5in,
            right=0.5in,
            top=0.85in,
            bottom=0.85in,
            footskip=0.5in]{geometry} 
        \usepackage{titling}
        \setlength{\droptitle}{-2cm}
        \clearpairofpagestyles
        \lohead*{\textbf{Stat-8010}}
        \cohead*{\textbf{Statistical Methods I}}
        \rohead*{\textbf{Spring 2025}}
        \cofoot*{\pagemark}
       
execute:
  warning: false
  message: false 
  error: false
  echo: true
---

# Intro
1.  This is a simple use of quarto.

    ```{r}
    x <- 1 + 1
    x
    ```

输出

out

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