Tricky issues with adding an appendix to an article #4581
Replies: 6 comments 12 replies
-
Ooh, here's a near-solution for approach two! Instead of using format:
pdf:
documentclass: article
number-sections: true
top-level-division: section The only issue now is that section-level "1: Actual article" that isn't technically a heading but is showing up as one in the structure. If there were some way to omit it from the document (both in the TOC and in the document itself), it would be perfect. |
Beta Was this translation helpful? Give feedback.
-
Assuming that one is using the single |
Beta Was this translation helpful? Give feedback.
-
Hi, Using the LaTeX approach from above it will generate the correct output for the first appendix but the counter is not reset for subsequent Appendices. Also the 'A' in ---
title: "Appendix_repro"
format: pdf
editor: visual
linenumbers: false
numbersections: true
project:
execute-dir: project
form:
crossref:
fig-title: Figure
fig-prefix: Figure
fig-labels: arabic
appendix-title: "Appendix:"
appendix-delim: ":"
sec-prefix: ""
---
```{=tex}
\appendix
\renewcommand{\thefigure}{A\arabic{figure}}
\renewcommand{\thetable}{A\arabic{table}}
\setcounter{figure}{0}
\setcounter{table}{0}
```
# 1st Appendix {.appendix}
| Col1 | Col2 | Col3 | Col4 |
|------|------|------| -----|
| A | B | C | D |
| E | F | G | H |
| I | J | K | L |
| M | N | O | P |
| Q | R | S | T |
| U | V | W | X |
| Y | Z | - | - |
: 1st Appendix table {#tbl-letters-full}
# 2nd Appendix {.appendix}
| Col1 | Col2 | Col3 | Col4 |
|------|------|------| -----|
| A | B | C | D |
| E | F | G | H |
| I | J | K | L |
| M | N | O | P |
| Q | R | S | T |
| U | V | W | X |
| Y | Z | - | - |
: 2nd Appendix table {#tbl-letters2-full}
A simple solution to this would be to repeat this LaTeX chunk at the start of each subsequent appendix to reset the counter and manually update the prefix but this is messy. A better solution I found is to use some additional LaTeX packages (included in the YAML below) and then include a LaTeX chunk at the start of the appendices as follows: ---
title: "Appendix_repro"
format: pdf
editor: visual
linenumbers: false
numbersections: true
project:
execute-dir: project
form:
crossref:
fig-title: Figure
fig-prefix: Figure
fig-labels: arabic
appendix-title: "Appendix:"
appendix-delim: ":"
sec-prefix: ""
header-includes:
- \usepackage[toc,title,page]{appendix}
- \usepackage{chngcntr}
---
```{=tex}
\appendix
\renewcommand{\thesection}{\Alph{section}}
\setcounter{section}{0}
\counterwithin{figure}{section}
\counterwithin{table}{section}
\begin{appendices}
```
# 1st Appendix {.appendix}
| Col1 | Col2 | Col3 | Col4 |
|------|------|------| -----|
| A | B | C | D |
| E | F | G | H |
| I | J | K | L |
| M | N | O | P |
| Q | R | S | T |
| U | V | W | X |
| Y | Z | - | - |
: 1st Appendix table {#tbl-letters-full}
# 2nd Appendix {.appendix}
| Col1 | Col2 | Col3 | Col4 |
|------|------|------| -----|
| A | B | C | D |
| E | F | G | H |
| I | J | K | L |
| M | N | O | P |
| Q | R | S | T |
| U | V | W | X |
| Y | Z | - | - |
: 2nd Appendix table {#tbl-letters2-full}
which gives the correct output and does not require additional chunks for subsequent appendices: |
Beta Was this translation helpful? Give feedback.
-
In Quarto 1.4, it's now possible to define custom crossreferencable types, so you can make a specific kind for appendix images or appendix tables, like this: ---
title: "Testing"
crossref:
custom:
- kind: float
prefix: Table A
space-before-numbering: false
name: Table A
ref-type: apptbl
latex-env: apptbl
latex-list-of-file-extension: lost
latex-list-of-description: Appendix Table
apptbl-cap-location: top
---
Here's the introduction. Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium.
# Theory
Totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo.
# Methods and data
Sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt.
## Data
See @tbl-letters for some of the columns; see @apptbl-letters-full in the appendix for all the columns.
| Col1 | Col2 | Col3 |
|------|------|------|
| A | B | C |
| E | F | G |
| A | G | G |
: Some letters {#tbl-letters}
## Modeling approach
$$
\hat{y} = \beta_0 + \beta_1 x_1 + \varepsilon
$$
# Results
## Plots
Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet.
## Model results
Consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem.
# Conclusion
Ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut aliquid ex ea commodi consequatur?
# Appendix {.appendix}
## Full data
::: {#apptbl-letters-full}
| Col1 | Col2 | Col3 | Col4 |
|------|------|------| -----|
| A | B | C | D |
| E | F | G | H |
| I | J | K | L |
| M | N | O | P |
| Q | R | S | T |
| U | V | W | X |
| Y | Z | - | - |
All the letters
:::
This creates a separate numbering system, so you get "Table 1" and "Table A1": And the table caption is numbered correctly: |
Beta Was this translation helpful? Give feedback.
-
Following on @andrewheiss' question, I tried to use Quarto 1.4's Custom Cross-Reference Types to reference entire Supplements (i.e., "For details, see Supplement 1. For information, see Supplement 2), rather than individual Tables or Figures. I aimed to also build on regular section referencing, i.e., I have tried to no avail:
and
How might I use the new cross-ref features to accomplish this? Many thanks for you help! |
Beta Was this translation helpful? Give feedback.
-
Take a look at figure-table-formatter. It moves the tables, figures, and supplements to wherever you indicate. You can cross-reference the figures and tables in the order that they are mentioned in the text, and sort them accordingly. It automatically outputs a file with the sorted tags of the figures and tables. You can use this file to automatically sort the figures in other files using the same filter (handy for supplements). It would be nice to have the same functionality in the native Quarto, but at least this is a viable alternative now. |
Beta Was this translation helpful? Give feedback.
-
When writing academic journal articles, it is common to have a supplemental appendix with extra figures/tables/math/etc.
Quarto supports a couple different ways for handling appendices, but they create inconsistent output across formats and I can’t figure out how to get them consistent :(
My ultimate goal is to get text that looks like this in both HTML and PDF (and ideally Word too):
…where “Table 1” doesn’t contain a chapter number like “Table 1.1”, and where “Table A.1” uses some sort of prefix and restarts at 1.
I've played with two different approaches to get this to work:
{.appendix}
to headingsappendices
sectionNeither works 100% consistently across all formats though. The single .qmd +
{.appendix}
approach works perfectly for PDFs but has issues with cross-reference numbering in HTML. The book approach works perfectly for HTML but has issues with document structure in PDF.Here are some reproducible examples of both approaches
Approach 1: Use a single .qmd file and add
{.appendix}
to headingsQuarto can create an automatic appendix section by adding the
{.appendix}
class to a heading. This moves the heading down the end of the document to a special section.Here’s a reproducible example:
manuscript.qmd
It looks like this:
Data subsection in the manuscript:
Appendix section at the end:
Downsides and workarounds
The table in the appendix is numbered as Table 2 and there’s no way to get “Table A1” since numbering is sequential throughout the document.
It is possible to use the
crossref: chapter
option to force numbering to restart in each H1……but this restarts cross references for each section, resulting in output like this:
In PDF output, it’s possible to work around the sequential numbering issue by including some LaTeX code to use the
\appendix
environment and restart numbering. If you add this right before the# Appendix
section……the resulting PDF shows the text correctly and the appendix starts on a new page at the end!
General summary
Using
{.appendix}
works great for PDF with some added LaTeX code. It almost works for HTML and Word, but there’s no way to get correctly-restarted cross-reference numbers.Approach 2: Use a Quarto book and use the
appendices
sectionQuarto books support parts and appendices and .qmd files can be included as appendices by using the
book: appendices
YAML key. Instead of writing an article in one .qmd file, the content can be spread across two .qmd files—one namedindex.qmd
that contains the main article, and one namedappendix.qmd
(or whatever else) that contains the appendix.Here’s a reproducible example with three separate files:
_quarto.yml
index.qmd
appendix.qmd
This works great for HTML output and creates a nice website structure for the article. The cross-reference numbering is also correct:
Downsides and workarounds
This gets a lot trickier with PDF output, though. Using the default
documentclass: srcreport
results in a PDF with a title page, an abstract page, a TOC page, and each H1 starting on its own page. The cross-reference numbering refers to chapter numbers:The document structure is also off. The TOC shows a part-level entry for “Appendices”, but the “Actual article” entry for the overall article is a chapter-level entry, not a part.
Most of these issues can be cleaned up by:
article
classarticle
doesn’t support\chapter{}
)\newpage
+\appendix
+ cross-reference number resetting LaTeX code to the end of index.qmd (but not at the beginning of appendix.qmd, since Quarto moves the title of that document prior to any of its content)This puts everything in an article-style document (with no chapters and no page breaks for each of the sections)…
…and it creates the correct cross-reference numbering:
However, the TOC shows chapter-level entries for “Actual article” and “Appendices”. In a perfect world, it would be great if “Actual article” could be omitted entirely and “Full data” could go under “Appendices” as a subsection, but doing this seems like it would require some fancy LaTeX editing (perhaps with a Lua filter)
General summary
Using a Quarto book with separate .qmd files for the main manuscript and the appendix works great for HTML. It almost works perfectly for PDF with some added LaTeX code and some adjustments to heading levels and the document class, but hardcoded faux chapter titles are impossible to remove.
Ways to fix these issues?
Phew. With all that, does anyone know if there's a way to fix either of these issues?
For approach 1 (single file with
{.appendix}
): Is there a way to control cross-reference numbering in HTML output so that figures/tables/sections in the appendix can restart, resulting in text that would look likeFor approach 2 (book with index.qmd + appendix.qmd): Is there a way to have more control over the document structure in the TOC and not include the "Main article" heading as a chapter/section and include the appendix as a subsection under "Appendices" (or whatever the user specifies in
language: en: section-title-appendices
)?Beta Was this translation helpful? Give feedback.
All reactions