Force Table Placement

Hello together,

I hope someone is smarter than me and can help me out on this one. I have a table, containing two sub tables. I created them using Markdown Language in Quarto. Now I am trying to find out, why the heck those tables are always placed at the top of the page.

Creating tables within an R chunk using kableExtra can handle the placement of such "simple" tables by using kableExtra::kable_styling(latex_options = 'HOLD_position'). But with plain Markdown (and I used it since I have no clue how to rewrite it in kableExtra) I cannot find any options that force the table placement where it should come (instead of the top of the page).

Here is the code producing a reprex .pdf document.

---
title: "Reprex"
format:
  pdf:
    documentclass: article
    classoption: a4paper
    number-sections: true
    tbl-cap-location: top
    mainfont: Arial
    sansfont: Arial
    lang: de
    include-in-header:
      text: |
        \usepackage{lipsum}
---

\cleardoublepage
\tableofcontents

\cleardoublepage
\pagenumbering{arabic}

\section{Reprex}

This is a short introductional sentence which is definitely not long enough to force a placement of the table at the top of the page.

::: {#tbl-Tabelle1 layout-ncol=2}
| ID   | Start | Ende | Zustand |
|------|-------|------|---------|
| 1    | 1     | 2    | Ausb    |
| 1    | 3     | 5    | svB     |
| 1    | 6     | 7    | gB      |
| 1    | 8     | 10   | svB     |
| 2    | 1     | 3    | Ausb    |
| 2    | 4     | 5    | kE      |
| 2    | 6     | 10   | ALO     |


: SPELL Format {#tbl-SPELL}

| ID   | Monat1 | Monat2 | Monat3 | ... | Monat10 |
|------|--------|--------|--------|-----|---------|
| 1    | Ausb   | Ausb   | svB    | ... | svB     |
| 2    | Ausb   | Ausb   | Ausb   | ... | ALO     |

: STS Format {#tbl-STS}

Übergang von SPELL in STS Format
:::

\lipsum[1]

And here are the tlmgr informations:

tlmgr revision 63068 (2022-04-18 07:58:07 +0200)
TeX Live (https://tug.org/texlive) version 2022

The goal would be to place the table below the first sentence, instead of above the header.

Kind regards

1 Like

I played a bit around and came to a correct placement with two modifications

  1. Rewrite the tables in data.frames and use kableExtra

  2. Specify `tbl-colum: page' in the execution options

But unfortunetaly the correct placement comes at the cost of shrinking the captions font size and misspositioning them... A second table is placed below to check for additional issues regarding placement of usual tables. Here is the actualized code:

---
title: "Reprex"
format:
  pdf:
    documentclass: article
    classoption: a4paper
    number-sections: true
    tbl-cap-location: top
    mainfont: Arial
    sansfont: Arial
    lang: de
    include-in-header:
      text: |
        \usepackage{lipsum}
---

\cleardoublepage
\tableofcontents

\cleardoublepage
\pagenumbering{arabic}

\section{Reprex}

This is a short introductional sentence which is definitely not long enough to force a placement of the table at the top of the page.


#| echo: false
#| label: tbl-Tabelle1
#| tbl-cap: Übergang von SPELL zu STS'
#| tbl-subcap: ['SPELL Format', 'STS Format']
#| layout: "[[1,1]]"
#| layout-align: center
#| tbl-column: page

data_SPELL <- data.frame(
  ID = c(1,1,1,1,2,2,2), Start = c(1,3,6,8,1,4,6), Ende = c(2,5,7,10,2,5,10), Zustand = c('Ausb','svB','gB','svB','Ausb','kE','ALO')
)

data_STS <- data.frame(
  ID = c(1,2),
  Monat1 = c('Ausb','Ausb'),
  Monat2 = c('Ausb','Ausb'),
  Monat3 = c('svB','Ausb'),
  `...`  = c('...','...'),
  Monat10 = c('svB','ALO')
)

data_SPELL |>
  kableExtra::kbl(format = 'latex', booktabs = TRUE, escape = FALSE) |>
  kableExtra::kable_styling(position = 'center',latex_options = 'HOLD_position')

data_STS |>
  kableExtra::kbl(format = 'latex', booktabs = TRUE, escape = FALSE) |>
  kableExtra::kable_styling(position = 'center',latex_options = 'HOLD_position')


\lipsum[1]


#| echo: false
#| label: tbl-Tabelle2
#| tbl-cap: 'Definierte Zustände'

data.frame(
  Index       = seq.default(1,by = 1,length.out = 7),
  Bezeichnung = c('Ausb','svB','gB','MT','ALO','Asu','kE'),
  Zustand     = c('Ausbildung',
                  'sozialversicherungspflichtige Beschäftigung',
                  'geringfügige Beschäftigung',
                  'Maßnahmeteilnahme',
                  paste0('Arbeitslos (SGB II/SGB III)',kableExtra::footnote_marker_number(1,format = 'latex',double_escape = FALSE)),
                  'Arbeitssuchend',
                  'kein Eintrag')
) |>
  kableExtra::kbl(format = 'latex', booktabs = TRUE, escape = FALSE) |>
  kableExtra::kable_styling(position = 'center',latex_options = 'HOLD_position') |>
  kableExtra::footnote(
    number = 'Der Bezug von Leistungen nach dem SGB II beschreibt den Erhalt der Grundsicherung für Arbeitslose. Demgegenüber regelt das SGB III den Leistungsbezug aus der Arbeitslosenversicherung nach Beendigung eines Erwerbsverhältnisses.',threeparttable = TRUE,fixed_small_size = TRUE)

Thanks for your interesting problem AND your solution.
Looking for a solution without the kableExtra package I saw a similar issue on the forum.
After following the suggestion of Ranae and adding to the yaml

    header-includes:
      - \usepackage{float}
      - \floatplacement{table}{H}

I got the table in the correct place (I think).
Of course this could bite the placement of other tables.

3 Likes

Thank you very much!! This was exactly the missing piece which places the table in the right place (as #| tbl-column: page does) but without missplacing and shrinking the caption. I don't know wether this is a bug or not (maybe I should open an issue on GitHub?), but your code perfectly solves the issue!

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.