Skip to content

In PDF output, code listings can float away from their annotations #5142

@dragonstyle

Description

@dragonstyle

The following document can result in the code listing floating away from its annotations:

---
title: Hello World
format: html
---

## Hello

{{< lipsum 1-2 >}}

```{#lst-customers .r lst-cap="Customers Query"}


# this is a comment that adds length to the code block
# this is a comment that adds length to the code block
# this is a comment that adds length to the code block

library(tidyverse)

# this is a comment that adds length to the code block
# this is a comment that adds length to the code block
# this is a comment that adds length to the code block

library(palmerpenguins)
penguins |>                                      # <1>
  mutate(                                        # <2>
    bill_ratio = bill_depth_mm / bill_length_mm, # <2>
    bill_area  = bill_depth_mm * bill_length_mm  # <2>
  )                                              # <2>
```
1. Take `penguins`, and then,
2. add new columns for the bill ratio and bill area.

{{< lipsum 3-4 >}}

note that we define the code listing environment as:

\\@ifundefined{c@chapter}{\\newfloat{codelisting}{h}{lop}}{\\newfloat{codelisting}{h}{lop}[chapter]}

We should create an option for float hold, always float hold, or do something smarter here.

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions