-
Notifications
You must be signed in to change notification settings - Fork 1k
Expand file tree
/
Copy patharticle-layout.qmd
More file actions
533 lines (395 loc) · 20.6 KB
/
article-layout.qmd
File metadata and controls
533 lines (395 loc) · 20.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
---
title: "Article Layout"
format: html
reference-location: margin
citation-location: margin
aliases:
- page-layout.html
---
## Overview
Quarto supports a variety of page layout options that enable you to author content that:
- Fills the main content region
- Overflows the content region
- Spans the entire page
- Occupies the document margin
- Uses landscape mode in paginated formats
Quarto uses the concept of columns to describe page layout (e.g. the "body" column, the "margin" column, etc.). Below we'll describe how to arrange content into these columns. If you need to adjust the widths of the columns, see [Page Layout - Grid Customization](/docs/output-formats/page-layout.qmd#grid-customization).
All of the layout capabilities described in this document work for HTML and Typst output. Many also work for PDF and LaTeX output, though with some differences. See [Typst Layout] and [PDF/LaTeX Layout] for format-specific details.
## Body Column
By default, elements are positioned in the body of the document and are allowed to span the content of the document, like the below.
::: {.layout-example .column-body}
.column-body
:::
But if you'd like, you can extend content slightly outside the bounds of the body by creating a div with the .`column-body-outset` class. For example:
``` markdown
:::{.column-body-outset}
Outset content...
:::
```
::: {.layout-example .column-body-outset}
.column-body-outset
:::
## Page Column
If you need even more space for your content, you can use the `.column-page` class to make the content much wider, though stopping short of extending across the whole document.
::: {.layout-example .column-page}
.column-page
:::
For example, to create a wider image, you could use:
``` markdown
:::{.column-page}

:::
```
::: column-page
{fig-alt="Three walking elephants in silhouette against the backdrop of a sunset."}
:::
For computational output, you can specify the page column in your code cell options. For example:
```{r}
#| column: page
#| echo: fenced
knitr::kable(
mtcars[1:6, 1:10]
)
```
In addition, you can use `.column-page-inset` to inset the element from the page slightly, like so:
::: {.layout-example .column-page-inset}
.column-page-inset
:::
## Screen Column
You can have content span the full width of the page with no margin (full bleed). For this, use the `.column-screen` class or specify `column: screen` on a code cell. For example:
``` md
::: {.column-screen}

:::
```
::: {.layout-example .column-screen}
.column-screen
:::
The following code displays a Leaflet map across the whole page.
```{r}
#| column: screen
#| echo: fenced
library(leaflet)
leaflet() %>%
addTiles() %>% # Add default OpenStreetMap map tiles
addMarkers(lng=174.768, lat=-36.852, popup="The birthplace of R")
```
### Screen Inset
If you'd like a full width appearance, but would like to retain a margin, you can use inset or inset-shaded modifiers on the column. For example:
``` md
::: {.column-screen-inset}

:::
```
::: {.layout-example .column-screen-inset}
.column-screen-inset
:::
The inset-shaded modifier results in a block spanning the full width but wrapped with a lightly shaded background. For example:
```{r}
#| column: screen-inset-shaded
#| echo: fenced
library(leaflet)
leaflet() %>%
addTiles() %>% # Add default OpenStreetMap map tiles
addMarkers(lng=174.768, lat=-36.852, popup="The birthplace of R")
```
Column layouts like `screen-inset-shaded` will work with advanced figure layout. For example, it is straightforward to create a multi column presentation of figures that spans the document:
```{r}
#| column: screen-inset-shaded
#| layout-nrow: 1
#| echo: fenced
plot(cars)
plot(iris)
plot(pressure)
```
## Margin Content
You can place content within the right margin of Quarto document. For example, here we use the `.column-margin` class to place an image in the margin:
``` md
::: {.column-margin}

:::
```
::: {.layout-example .column-margin style="margin-top: 18px;"}
.column-margin
:::
This also works for text content:
``` md
::: {.column-margin}
We know from *the first fundamental theorem of calculus* that for $x$ in $[a, b]$:
$$\frac{d}{dx}\left( \int_{a}^{x} f(u)\,du\right)=f(x).$$
:::
```
::: column-margin
We know from *the first fundamental theorem of calculus* that for $x$ in $[a, b]$:
$$\frac{d}{dx}\left( \int_{a}^{x} f(u)\,du\right)=f(x).$$
:::
### Margin Figures
Figures that you create using code cells can be placed in the margin by using the `column: margin` code cell option. If the code produces more than one figure, each of the figures will be placed in the margin.
```{r}
#| label: fig-mtcars
#| fig-cap: "MPG vs horsepower, colored by transmission."
#| column: margin
#| echo: fenced
library(ggplot2)
mtcars2 <- mtcars
mtcars2$am <- factor(
mtcars$am, labels = c('automatic', 'manual')
)
ggplot(mtcars2, aes(hp, mpg, color = am)) +
geom_point() +
geom_smooth(formula = y ~ x, method = "loess") +
theme(legend.position = 'bottom')
```
### Margin Tables
You can also place tables in the margin of your document by specifying `column: margin`.
```{r}
#| column: margin
#| echo: fenced
knitr::kable(
mtcars[1:6, 1:3]
)
```
### Multiple Outputs
You can also target specific output types (for example, figures) to be placed in the margin. For example, the following code will render a table showing part of the `mtcars` dataset and produce a plot in the margin next to the table.
```{r}
#| fig-column: margin
#| echo: fenced
mtcars2 <- mtcars
mtcars2$am <- factor(
mtcars$am, labels = c('automatic', 'manual')
)
knitr::kable(
mtcars[1:6, 1:6]
)
library(ggplot2)
ggplot(mtcars2, aes(hp, mpg, color = am)) +
geom_point() +
geom_smooth(formula = y ~ x, method = "loess") +
theme(legend.position = 'bottom')
```
{{< include _pagebreak.qmd >}}
## Margin References
Footnotes and the bibliography typically appear at the end of the document, but you can choose to have them placed in the margin by setting the following option[^1] in the document front matter:
``` yaml
---
reference-location: margin
citation-location: margin
---
```
With these options set, footnotes and citations will (respectively) be automatically be placed in the margin of the document rather than the bottom of the page. As an example, when I cite @xie2018, the citation bibliography entry itself will now appear in the margin.
### Asides
Asides allow you to place content aside from the content it is placed in. Asides look like footnotes, but do not include the footnote mark (the superscript number). [This is a span that has the class `aside` which places it in the margin without a footnote number.]{.aside}
``` markdown
[This is a span that has the class `aside` which places it in the margin without a footnote number.]{.aside}
```
## Margin Captions
For figures and tables, you may leave the content in the body of the document while placing the caption in the margin of the document. Using `cap-location: margin` in a code cell or document front matter to control this. For example:
```{r}
#| label: fig-cap-margin
#| fig-cap: "MPG vs horsepower, colored by transmission."
#| cap-location: margin
#| echo: fenced
library(ggplot2)
mtcars2 <- mtcars
mtcars2$am <- factor(
mtcars$am, labels = c('automatic', 'manual')
)
ggplot(mtcars2, aes(hp, mpg, color = am)) +
geom_point() +
geom_smooth(formula = y ~ x, method = "loess") +
theme(legend.position = 'bottom')
```
## Overflowing Content
You can also extend content outside the body region on only the left or right side of the document by using the `right` and `left` versions of the `body`, `page`, and `screen` columns to layout your content. The `left` or `right` version of these columns are as follows:
::: {.layout-example .column-body-outset-right .left}
.column-body-outset-right
:::
::: {.layout-example .column-page-inset-right .left}
.column-page-inset-right
:::
::: {.layout-example .column-page-right .left}
.column-page-right
:::
::: {.layout-example .column-screen-inset-right .left}
.column-screen-inset-right
:::
::: {.layout-example .column-screen-right .left}
.column-screen-right
:::
::: {.layout-example .column-body-outset-left .right}
.column-body-outset-left
:::
::: {.layout-example .column-page-inset-left .right}
.column-page-inset-left
:::
::: {.layout-example .column-page-left .right}
.column-page-left
:::
::: {.layout-example .column-screen-inset-left .right}
.column-screen-inset-left
:::
::: {.layout-example .column-screen-left .right}
.column-screen-left
:::
Use a div with one of the above classes to align content into one of the overflow regions. This also works using the `column` option of executable code cells:
```{r}
#| column: screen-inset-right
#| echo: fenced
library(leaflet)
leaflet() %>%
addTiles() %>% # Add default OpenStreetMap map tiles
addMarkers(lng=174.768, lat=-36.852, popup="The birthplace of R")
```
## Options Reference
### Global Options
Some layout options can be specified globally in document yaml. For example:
``` yaml
---
fig-cap-location: margin
reference-location: margin
---
```
All of the below options currently only support setting a value of `margin` which tells Quarto to place the corresponding element in the margin.
+----------------------+---------------------------------------------------------------------------------------------------------+
| Option | Description |
+======================+=========================================================================================================+
| `reference-location` | Where to place footnotes. Defaults to `document`.[^2]\ |
| | \[`document` \| `section` \| `block` \| `margin` \] |
+----------------------+---------------------------------------------------------------------------------------------------------+
| `citation-location` | Where to place citations. Defaults to `document`.\ |
| | \[`document` \| `margin` \] |
+----------------------+---------------------------------------------------------------------------------------------------------+
| `cap-location` | Where to place figure and table captions. Defaults to `bottom` for figures and `top` for tables.\ |
| | \[`top` \| `bottom` \| `margin`\] |
+----------------------+---------------------------------------------------------------------------------------------------------+
| `fig-cap-location` | Where to place figure captions. Defaults to `bottom`.\ |
| | \[`top` \| `bottom` \| `margin`\] |
+----------------------+---------------------------------------------------------------------------------------------------------+
| `tbl-cap-location` | Where to place table captions. Defaults to `top`.\ |
| | \[`top` \| `bottom` \| `margin`\] |
+----------------------+---------------------------------------------------------------------------------------------------------+
### Code Cell Options
You can also set layout column on specific code cells. This controls the layout of content that is produced by the code cell.
```{{r}}
#| column: page
plot(cars)
```
::: column-page-right
+--------------------+------------------------------------------------------------------------------------------------------------------------------+
| Option | Description |
+====================+==============================================================================================================================+
| `column` | Layout column to use for code cell outputs. See column options below. |
+--------------------+------------------------------------------------------------------------------------------------------------------------------+
| `fig-column` | Layout column to use for code cell figure outputs. See column options below. |
+--------------------+------------------------------------------------------------------------------------------------------------------------------+
| `tbl-column` | Layout column to use for code cell table outputs. See column options below. |
+--------------------+------------------------------------------------------------------------------------------------------------------------------+
| `cap-location` | Where to place figure and table captions produced by this code cell. Defaults to `bottom` for figures and `top` for tables.\ |
| | \[`top` \| `bottom` \| `margin`\] |
+--------------------+------------------------------------------------------------------------------------------------------------------------------+
| `fig-cap-location` | Where to place captions for figures produced by this code cell. Defaults to `inline`.\ |
| | \[`inline` \| `margin`\] |
+--------------------+------------------------------------------------------------------------------------------------------------------------------+
| `tbl-cap-location` | Where to place captions for tables produced by this code cell. Defaults to `inline`.\ |
| | \[`inline` \| `margin`\] |
+--------------------+------------------------------------------------------------------------------------------------------------------------------+
:::
### Using Classes
In addition to global and code cell specific options, you may use divs with layout classes (prefixed with `.column-`) to arrange content into columns:
``` md
::: {.column-margin}
This content will appear in the margin!
:::
```
### Available Columns
Here are all of the available column specifiers:
::: column-page-right
+--------------+---------------------------------+---------------------------------+
| Column | Code Cell `column` | Class Name |
+==============+=================================+=================================+
| Body | column: body | .column-body |
| | column: body-outset | .column-body-outset |
| | column: body-outset-left | .column-body-outset-left |
| | column: body-outset-right | .column-body-outset-right |
+--------------+---------------------------------+---------------------------------+
| Page Inset | column: page-inset | .column-page-inset |
| | column: page-inset-left | .column-page-inset-left |
| | column: page-inset-right | .column-page-inset-right |
+--------------+---------------------------------+---------------------------------+
| Page | column: page | .column-page |
| | column: page-left | .column-page-left |
| | column: page-right | .column-page-right |
+--------------+---------------------------------+---------------------------------+
| Screen Inset | column: screen-inset | .column-screen-inset |
| | column: screen-inset-shaded | .column-screen-inset-shaded |
| | column: screen-inset-left | .column-screen-inset-left |
| | column: screen-inset-right | .column-screen-inset-right |
+--------------+---------------------------------+---------------------------------+
| Screen | column: screen | .column-screen |
| | column: screen-left | .column-screen-left |
| | column: screen-right | .column-screen-right |
+--------------+---------------------------------+---------------------------------+
| Margin | column: margin | .column-margin |
+--------------+---------------------------------+---------------------------------+
:::
## PDF/LaTeX Layout {data-link="PDF/LaTeX Layout"}
While most of the layout capabilities described are supported for both HTML and PDF output, some are available only for HTML output. You can use the full set of columns for HTML. Then, when you render PDF or LaTeX output, content will automatically be placed in the most appropriate related column (typically this will mean using the main column and right margin). Here is how columns are mapped:
- Any column that uses the right margin (e.g. `page`, `screen`, `screen-right`, etc.) will be rendered as `page-right` in LaTeX.
- Any column that uses the left margin will be rendered as normal body content.
### Page Geometry
When you render a PDF using content in the margin or content that spans the page, Quarto will automatically adjust the page geometry for the default Quarto LaTeX document classes (KOMA `scrartcl`, `scrreport`, or `scrbook`) to create a slightly narrower body content region and a slightly wider margin region. This adjustment will incorporate known paper sizes to create a reasonable page geometry for most content.
You can control the page geometry directly yourself by setting `geometry` options in your document's front matter. For example:
``` yaml
---
geometry:
- left=.75in
- textwidth=4.5in
- marginparsep=.25in
- marginparwidth=2.25in
---
```
You can use these options to control the page geometry for the built-in document classes or to customize the geometry of other document classes that you may be using.
::: {.callout-tip appearance="simple"}
If you'd like to view the page geometry in your rendered PDF, you can pass `showframe` to the `geometry` option as in the below example.
``` {.yaml style="background: none;"}
---
geometry:
- showframe
---
```
:::
### Code Blocks
When rendering a PDF that uses the margins for content, Quarto automatically adjusts the appearance of code blocks. Rather than having a solid background color, a left border treatment is used.
This enables non-breaking code to overflow into the margin without cosmetic issues created by the code block background (which does not overflow into the margin region).
You can disable this treatment by setting the following `code-block-border-left: false` in your document front matter.
## Typst Layout {#typst-layout data-link="Typst Layout"}
Typst output supports the layout capabilities described in this document via the [Marginalia](https://typst.app/universe/package/marginalia) package.
### Page Geometry
When you use margin content in a Typst document, Quarto automatically calculates appropriate page geometry based on your `papersize` setting. The geometry creates a narrower body column and a margin column for notes and figures.
You can customize the column widths using the `grid` option:
``` yaml
format:
typst:
grid:
margin-width: 2in
body-width: 4in
gutter-width: 0.25in
```
For fine-grained control over margin placement, Typst also provides the `margin-geometry` option which directly configures the underlying Marginalia package. See [Typst Basics - Article Layout](/docs/output-formats/typst.qmd#article-layout) for details.
## Landscape mode
In `docx`, `pdf` and `typst` formats, you can set portions of the document to landscape mode by wrapping the content around a fenced div with class `landscape`:
````markdown
---
format:
docx: default
typst: default
pdf: default
---
This will appear in portrait mode.
::: {.landscape}
This will appear in landscape.
:::
This will appear in portrait mode again.
````
[^1]: You can also position references in other location (such as the bottom of the block, section, or document).
[^2]: Typst does not support `block` or `section` for `reference-location`.