### Bug description

````markdown
---
format: pdf
keep-md: true
keep-tex: true
---

```{r}
#| label: tbl-iris
#| tbl-cap: "Iris Data"
library(knitr)
kable(head(iris), format = "latex", table.envir = "table", position = "h!")
```
````

**knitr** will generate table in LaTeX, with a specific table option, and Quarto will insert caption in the wrong place, as the option filed is not taken into account in our regex matching probably

````latex
\begin{table}
\caption{\label{tbl-iris}Iris Data }\tabularnewline
[h!]

\begin{tabular}{r|r|r|r|l}
\hline
Sepal.Length & Sepal.Width & Petal.Length & Petal.Width & Species\\
\hline
5.1 & 3.5 & 1.4 & 0.2 & setosa\\
\hline
4.9 & 3.0 & 1.4 & 0.2 & setosa\\
\hline
4.7 & 3.2 & 1.3 & 0.2 & setosa\\
\hline
4.6 & 3.1 & 1.5 & 0.2 & setosa\\
\hline
5.0 & 3.6 & 1.4 & 0.2 & setosa\\
\hline
5.4 & 3.9 & 1.7 & 0.4 & setosa\\
\hline
\end{tabular}
\end{table}
````

We fixed some issues like that in the past, and we probably missed some cases

First reported in https://github.com/quarto-dev/quarto-cli/discussions/2264#discussioncomment-3541972

### Checklist

- [ ] Please include a minimal, fully reproducible example in a single .qmd file? Please provide the whole file rather than the snippet you believe is causing the issue.
- [ ] Please [format your issue](https://yihui.org/issue/#please-format-your-issue-correctly) so it is easier for us to read the bug report.
- [ ] Please document the RStudio IDE version you're running (if applicable), by providing the value displayed in the "About RStudio" main menu dialog?
- [ ] Please document the operating system you're running. If on Linux, please provide the specific distribution.
cderv
2022-09-05T09:00:20Z
cderv
bug
closed
Table caption inserted in wrong place in LaTeX table
https://github.com/quarto-dev/quarto-cli/issues/2295