---
title: "Subtables in Margin"
papersize: us-letter
format:
  html: default
  typst:
    keep-typ: true
_quarto:
  tests:
    typst:
      ensureTypstFileRegexMatches:
        # Should have note() wrapping quarto_super for margin subtable placement
        - ['#note\(', 'quarto_super']
        - []
      ensurePdfRegexMatches:
        # Subtable labels, main table label, and subtable numbering together
        - ['Table 1', 'SUBTBL-PANEL', '\(a\) Asia', '\(b\) Americas']
        - []
      ensurePdfTextPositions:
        - # Subtable panel in margin
          - subject: "Asia"
            relation: rightOf
            object: "This tests"
          - subject: "Americas"
            relation: rightOf
            object: "This tests"
          # Asia table is above Americas table (vertical ordering)
          - subject: "Asia"
            relation: above
            object: "Americas"
          # Main table caption is above Asia (caption at top for tables)
          - subject: "SUBTBL-PANEL"
            relation: above
            object: "Asia"
        - []
      noErrors: default
---

This tests subtables (panel tables) placed in the margin from a single code block.

```{python}
#| column: margin
#| label: tbl-margin-panel
#| tbl-cap: "SUBTBL-PANEL: Two subtables in margin"
#| tbl-subcap:
#|   - "Asia"
#|   - "Americas"
#| echo: false
#| classes: plain

from great_tables import GT
import pandas as pd
from IPython.display import display

asia_data = pd.DataFrame({
    "Country": ["China", "India", "Japan"],
    "Pop (M)": [1400, 1380, 125]
})
display(GT(asia_data))

americas_data = pd.DataFrame({
    "Country": ["USA", "Brazil", "Mexico"],
    "Pop (M)": [330, 215, 130]
})
display(GT(americas_data))
```

Reference to @tbl-margin-panel shows the panel.

More text in the main column to show the layout alongside the margin subtables.
