1

I try to place a talltblr environment from Tabularray inside a table environment. However, this is messing up the pagebreak from the longtblr table above it. It somehow ends up inside the longtblr. The same thing happens when I change talltblr to tblr. I assumed the table environment would give me a better page layout (verticle space, placement etc). Is it not recommended to place a tblr inside a table environment?

See the MWE below and a picture of the outcome with and without the table environment wrapped around (tall)tblr. Blue header of longtblr, red header of talltblr.

\documentclass{article}

\usepackage{xcolor}% Colors
\usepackage{tabularray}%
    \UseTblrLibrary{amsmath,booktabs}%

%--------------------------------------------------------------%
\begin{document}
%--------------------------------------------------------------%
\section{Long table error}

Text needed 1?

\begin{longtblr}[
    caption = {Long tblr caption},% Caption
]{
    colspec = {lX},
    rowhead = 1,%               # rows footer, header
        hline{1,Z}  = {1pt},%   top & bottomrule
        hline{2}    = {0.3pt},% midrule
        row{1}      = {cyan},
}
% Header
    Head 1      & Head 2 \\
% Table
    AA          & 1 \\
    BB          & 2 \\
    CC          & 3 \\
    DD          & 4 \\
            \hline
    AA          & 1 \\
    BB          & 2 \\
    CC          & 3 \\
    DD          & 4 \\
            \hline
    AA          & 1 \\
    BB          & 2 \\
    CC          & 3 \\
    DD          & 4 \\
            \hline
    AA          & 1 \\
    BB          & 2 \\
    CC          & 3 \\
    DD          & 4 \\
            \hline
    AA          & 1 \\
    BB          & 2 \\
    CC          & 3 \\
    DD          & 4 \\
            \hline
    AA          & 1 \\
    BB          & 2 \\
    CC          & 3 \\
    DD          & 4 \\
            \hline
    AA          & 1 \\
    BB          & 2 \\
    CC          & 3 \\
    DD          & 4 \\
            \hline
    AA          & 1 \\
    BB          & 2 \\
    CC          & 3 \\
    DD          & 4 \\
            \hline
    AA          & 1 \\
    BB          & 2 \\
    CC          & 3 \\
    DD          & 4 \\
\end{longtblr}

Text needed 2?

\begin{table}
  \begin{talltblr}[
    caption = {Tall tblr caption},% Caption
]{
    colspec     = {ll},
        hline{1,Z}  = {1pt},%   top & bottomrule
        hline{2}    = {0.3pt},% midrule
        row{1}      = {purple},
}
% Header
    Head 1      & Head 2 \\
% Table
    AA          & 1 \\
    BB          & 2 \\
    CC          & 3 \\
    DD          & 4 \\
            \hline
    AA          & 1 \\
    BB          & 2 \\
    CC          & 3 \\
    DD          & 4 \\
            \hline
    AA          & 1 \\
    BB          & 2 \\
    CC          & 3 \\
    DD          & 4 \\
  \end{talltblr}
\end{table}

Text needed 3?

\end{document}

With table environment: Blue header of longtblr, red header of talltblr. With table 1With table 2

Without table environment: Blue header of longtblr, red header of talltblr. Without table 1Without table 2

1
  • 4
    table is a float, and so it can float to the top of the page. When you mix floating and non floating tables then it can happen that you have to correct the placement to get the numbering and order right. Commented Feb 10, 2022 at 22:39

1 Answer 1

2

Many users would think it is a trap when they discover some day that the default option of a table environment is tbp without h in it, which tell LaTeX not to try to put the table "here" (current position).

In most of the time it is a good idea to set the placement option of a table environment to !htbp. In this example, !hbp is a better choice, since it is after a long table.

\documentclass{article}

\usepackage{xcolor}% Colors
\usepackage{tabularray}%
\UseTblrLibrary{amsmath,booktabs}%

%--------------------------------------------------------------%
\begin{document}
%--------------------------------------------------------------%
\section{Long table error}

Text needed 1?

\begin{longtblr}[
    caption = {Long tblr caption},% Caption
]{
    colspec = {lX},
    rowhead = 1,%               # rows footer, header
        hline{1,Z}  = {1pt},%   top & bottomrule
        hline{2}    = {0.3pt},% midrule
        row{1}      = {cyan},
}
% Header
    Head 1      & Head 2 \\
% Table
    AA          & 1 \\
    BB          & 2 \\
    CC          & 3 \\
    DD          & 4 \\
            \hline
    AA          & 1 \\
    BB          & 2 \\
    CC          & 3 \\
    DD          & 4 \\
            \hline
    AA          & 1 \\
    BB          & 2 \\
    CC          & 3 \\
    DD          & 4 \\
            \hline
    AA          & 1 \\
    BB          & 2 \\
    CC          & 3 \\
    DD          & 4 \\
            \hline
    AA          & 1 \\
    BB          & 2 \\
    CC          & 3 \\
    DD          & 4 \\
            \hline
    AA          & 1 \\
    BB          & 2 \\
    CC          & 3 \\
    DD          & 4 \\
            \hline
    AA          & 1 \\
    BB          & 2 \\
    CC          & 3 \\
    DD          & 4 \\
            \hline
    AA          & 1 \\
    BB          & 2 \\
    CC          & 3 \\
    DD          & 4 \\
            \hline
    AA          & 1 \\
    BB          & 2 \\
    CC          & 3 \\
    DD          & 4 \\
\end{longtblr}

Text needed 2?

\begin{table}[!hbp]
  \begin{talltblr}[
    caption = {Tall tblr caption},% Caption
]{
    colspec     = {ll},
        hline{1,Z}  = {1pt},%   top & bottomrule
        hline{2}    = {0.3pt},% midrule
        row{1}      = {purple},
}
% Header
    Head 1      & Head 2 \\
% Table
    AA          & 1 \\
    BB          & 2 \\
    CC          & 3 \\
    DD          & 4 \\
            \hline
    AA          & 1 \\
    BB          & 2 \\
    CC          & 3 \\
    DD          & 4 \\
            \hline
    AA          & 1 \\
    BB          & 2 \\
    CC          & 3 \\
    DD          & 4 \\
  \end{talltblr}
\end{table}

Text needed 3?

\end{document}

enter image description here

For better control of the position of a table environment, you may see answers to these questions:

How to influence the position of float environments like figure and table in LaTeX?

Keeping tables/figures close to where they are mentioned

There is also an issue about clearing floats before a longtblr environment:

https://github.com/lvjr/tabularray/issues/60

3
  • Thank you very much for this solution to my problem! Would you advice to place a float block for all the longtblrs instead of controlling the position of the tables? For example like this: \AddToHook{env/longtblr/begin}{\FloatBlock}
    – Elise
    Commented Feb 11, 2022 at 13:43
  • @Elise I can not answer this because I haven’t done any test in long documents.
    – L.J.R.
    Commented Feb 11, 2022 at 14:23
  • That is not a problem. Thank you very much for your solution!
    – Elise
    Commented Feb 11, 2022 at 16:07

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .