0

Problem & MWE

I would like to add a simple tabular table (as described in Overleaf), inside a longtblr table (as proposed/built up by @CarLaTeX in another stack exchange question).

As shown in the following MWE and in the corresponding figure, where I added the simple tabular table (as indicated in Overleaf) inside my longtblr table, we can notice that:

  1. the black lines forming the tabular table are not shown, and
  2. the longtblr table is not centered anymore.
% The original "longtblr" table was created by @CarLaTeX in 
% https://tex.stackexchange.com/questions/675559/how-to-draw-horizontal-rules-lines-beginning-in-column-i-and-ending-in-column-j

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[dvipsnames,table]{xcolor}
\definecolor{light-gray}{HTML}{FFFFFF}
\definecolor{light-blue}{HTML}{EBF5FB}
\usepackage{tabularray}

\title{}
\author{}

\begin{document}
    \maketitle
    
    \begin{longtblr}[
        caption = {This is a caption.},
        ]{
            colspec={m{1.2cm} m{0.5cm} m{1cm} m{1.5cm} m{1.5cm} m{4cm} m{1.5cm}},
            row{1}={font=\itshape},
            row{2,5-7}={bg=light-blue},
            row{3-4}={bg=light-gray},
            hlines
        }
        & Day
        & Month
        & Hours
        & Feature 1 
        & Feature 2
        & Feature 3\\
        %-------------------------------------------------
        Friday
        & 5 
        & June
        & 
        & A\textsubscript{1}
        & % A\textsubscript{2}
        \begin{center}
            \begin{tabular}{ |c|c|c| } 
             \hline
             cell1 & cell2 & cell3 \\ 
             cell4 & cell5 & cell6 \\ 
             cell7 & cell8 & cell9 \\ 
             \hline
            \end{tabular}
        \end{center}
        & A\textsubscript{3}
        \\
        %-------------------------------------------------
        \SetCell[r=2]{l} Saturday 
        & \SetCell[r=2]{l} 6 
        & \SetCell[r=2]{l} June
        & 14 -- 21
        & B\textsubscript{1}
        &
        & B\textsubscript{3}
        \\
        &  
        & 
        &
        & C\textsubscript{1}
        & C\textsubscript{2}
        & C\textsubscript{3}
        \\
        % -------------------------------------------------
        \SetCell[r=3]{l} Sunday
        & \SetCell[r=3]{l} 7
        & \SetCell[r=3]{l} June
        & 08 -- 10
        & D\textsubscript{1}
        & D\textsubscript{2}
        & D\textsubscript{3}
        \\
        & 
        &
        & 10 -- 17
        & E\textsubscript{1}
        &
        & E\textsubscript{3}
        \\
        & 
        & 
        & 
        & F\textsubscript{1}
        & F\textsubscript{2}
        & F\textsubscript{3}
        \\
        % -------------------------------------------------
    \end{longtblr}
    
\end{document}

enter image description here

Questions

Just by adding that simple tabular table, as shown in Overleaf, inside my longtblr table, we can see that the black lines forming the tabular table are not shown. Also the longtblr table is not centered anymore.

  1. How can I show the black lines forming the tabular table?
  2. How can I re-center the entire longtblr table?

Desired Output for the "tabular" table inside the "longtblr" table.

The "tabular" table should have borders as shown here:

enter image description here

1st Editing, after the @Jasper Habicht answer

Hello @Jasper Habicht, by using your solution, I have noticed that, if I add some text before and after the tblr environment,

\begin{tblr}{ |c|c|c| }
   \hline
   cell1 & cell2 & cell3 \\ 
   cell4 & cell5 & cell6 \\ 
   cell7 & cell8 & cell9 \\ 
   \hline
\end{tblr}

the text in the other columns (but in the same row) goes up to the top of the row, i.e. is not vertically aligned as before. In addition, in the same column where there is now the tblr table, I can see some empty space at the bottom of the row, I mean before reaching the \hline, i.e. under my text which is just below the tblr table...

Please see here below the MWE and the corresponding figure:

enter image description here

\documentclass{article}
\usepackage[margin=2cm]{geometry}
\usepackage[dvipsnames,table]{xcolor}
\definecolor{light-gray}{HTML}{FFFFFF}
\definecolor{light-blue}{HTML}{EBF5FB}
\usepackage{tabularray}

\begin{document}

    {\centering Centered Text\par}
    
    \begin{longtblr}[
        caption = {This is a caption.},
        ]{
            colspec={m{1.2cm} m{0.5cm} m{1cm} m{1cm} m{1.5cm} m{3.5cm} m{1.5cm}},
            cells={font=\small},
            row{1}={font=\itshape\small},
            row{2,5-7}={bg=light-blue},
            row{3-4}={bg=light-gray},
            hlines
        }
        & Day
        & Month
        & Hours
        & Feature 1 
        & Feature 2
        & Feature 3\\
        %-------------------------------------------------
        Friday
        & 5 
        & June
        & 
        & A\textsubscript{1}
        & This is a long text that will be repeated many times. This is a long text that will be repeated many times. This is a long text that will be repeated many times. This is a long text that will be repeated many times. This is a long text that will be repeated many times. This is a long text that will be repeated many times. This is a long text that will be repeated many times. This is a long text that will be repeated many times. This is a long text that will be repeated many times. 
        \begin{tblr}{ |c|c|c| }
            \hline
             cell1 & cell2 & cell3 \\ 
             cell4 & cell5 & cell6 \\ 
             cell7 & cell8 & cell9 \\ 
             \hline
        \end{tblr}
        This is a long text that will be repeated many times. This is a long text that will be repeated many times. This is a long text that will be repeated many times. 
        & A\textsubscript{3}
        \\
        %-------------------------------------------------
        \SetCell[r=2]{l} Saturday 
        & \SetCell[r=2]{l} 6 
        & \SetCell[r=2]{l} June
        & 14 -- 21
        & B\textsubscript{1}
        &
        & B\textsubscript{3}
        \\
        &  
        & 
        &
        & C\textsubscript{1}
        & C\textsubscript{2}
        & C\textsubscript{3}
        \\
        % -------------------------------------------------
        \SetCell[r=3]{l} Sunday
        & \SetCell[r=3]{l} 7
        & \SetCell[r=3]{l} June
        & 08 -- 10
        & D\textsubscript{1}
        & D\textsubscript{2}
        & D\textsubscript{3}
        \\
        & 
        &
        & 10 -- 17
        & E\textsubscript{1}
        &
        & E\textsubscript{3}
        \\
        & 
        & 
        & 
        & F\textsubscript{1}
        & F\textsubscript{2}
        & F\textsubscript{3}
        \\
        % -------------------------------------------------
    \end{longtblr}
    
\end{document}

2nd Editing

I have just copied and pasted

column{6}={preto={\begin{minipage}{3.5cm}}, appto={\end{minipage}}}

here:

\documentclass{article}
\usepackage[margin=2cm]{geometry}
\usepackage[dvipsnames,table]{xcolor}
\definecolor{light-gray}{HTML}{FFFFFF}
\definecolor{light-blue}{HTML}{EBF5FB}
\usepackage{tabularray}

\begin{document}

    {\centering Centered Text\par}
    
    \begin{longtblr}[
        caption = {This is a caption.},
        ]{
            colspec={m{1.2cm} m{0.5cm} m{1cm} m{1cm} m{1.5cm} m{3.5cm} m{1.5cm}},
            cells={font=\small},
            row{1}={font=\itshape\small},
            row{2,5-7}={bg=light-blue},
            row{3-4}={bg=light-gray},
            column{6}={preto={\begin{minipage}{3.5cm}}, appto={\end{minipage}}}
            hlines
        }
        & Day
        & Month
        & Hours
        & Feature 1 
        & Feature 2
        & Feature 3\\
        %-------------------------------------------------
        Friday
        & 5 
        & June
        & 
        & A\textsubscript{1}
        & This is a long text that will be repeated many times. This is a long text that will be repeated many times. This is a long text that will be repeated many times. This is a long text that will be repeated many times. This is a long text that will be repeated many times. This is a long text that will be repeated many times. This is a long text that will be repeated many times. This is a long text that will be repeated many times. This is a long text that will be repeated many times. 
        \begin{tblr}{ |c|c|c| }
            \hline
             cell1 & cell2 & cell3 \\ 
             cell4 & cell5 & cell6 \\ 
             cell7 & cell8 & cell9 \\ 
             \hline
        \end{tblr}
        This is a long text that will be repeated many times. This is a long text that will be repeated many times. This is a long text that will be repeated many times. 
        & A\textsubscript{3}
        \\
        %-------------------------------------------------
        \SetCell[r=2]{l} Saturday 
        & \SetCell[r=2]{l} 6 
        & \SetCell[r=2]{l} June
        & 14 -- 21
        & B\textsubscript{1}
        &
        & B\textsubscript{3}
        \\
        &  
        & 
        &
        & C\textsubscript{1}
        & C\textsubscript{2}
        & C\textsubscript{3}
        \\
        % -------------------------------------------------
        \SetCell[r=3]{l} Sunday
        & \SetCell[r=3]{l} 7
        & \SetCell[r=3]{l} June
        & 08 -- 10
        & D\textsubscript{1}
        & D\textsubscript{2}
        & D\textsubscript{3}
        \\
        & 
        &
        & 10 -- 17
        & E\textsubscript{1}
        &
        & E\textsubscript{3}
        \\
        & 
        & 
        & 
        & F\textsubscript{1}
        & F\textsubscript{2}
        & F\textsubscript{3}
        \\
        % -------------------------------------------------
    \end{longtblr}
    
\end{document}

But I got this:

enter image description here enter image description here

3rd Editing

By replacing this command

column{6}={preto={\begin{minipage}{3.5cm}}, appto={\end{minipage}}}

with this one,

column{6}={preto={\minipage{3.5cm}}, appto={\endminipage}},

all the warnings disappear!

Many thanks @Jasper Habicht!

10
  • 1
    Maybe you first explain what the final output should look like. Nesting tables ist never an easy thing. Now it rather looks that you want to place arbitrary code in the cell. If this is what you are after, try to place this stuff inside a box (a minipage for instance). Feb 28, 2023 at 18:28
  • Yes, you are right, I did not say that I needed some text before or after that table... I thought it was not necessary and it could make the question a bit heavier, so I neglected it... Ok, I try with minipage, many thanks!! :-)
    – Ommo
    Feb 28, 2023 at 18:33
  • 1
    I edited my answer and provided another working solution with your latest code snippet. Feb 28, 2023 at 18:54
  • 1
    The syntax errors you get are just there, because the editor thinks they are errors. LaTeX won't complain. You can replace \begin{minipage}{3.5cm} by \minipage{3.5cm} and \end{minipage} by \endminipage if you find these warnings too annoying. Also note that you are missing a comma before the last option (hlines). Feb 28, 2023 at 19:54
  • 1
    Yes, sorry I forgot the end... I used this one: column{6}={preto={\minipage{3.5cm}}, appto={\endminipage}}, :-)
    – Ommo
    Mar 1, 2023 at 9:31

1 Answer 1

1

If you really need to nest tables, you should place a tblr inside a longtblr (or inside another tblr) and not nest tabulars inside. The reason is that tblr (and longtblr) environments are typeset quite differently from tabulars, which is probably the reason for the problems that might occur if you nest one of the latter inside one of the former. Replacing the tabular environment in your code by a tblr environment solves the problem with the cell borders.

Also, you should probably not use a center environment inside a tblr cell. Rather, use the packages capabilities of centering text in specific cells using options. I did not show this in my solution because I don't think that centering the nested table is even necessary.

As for the question why your table is not centered, the answer is just: It is too wide. I cannot help you in this regard, but maybe reducing the page margins or choosing a smaller font can help you. In the end, your table should not be wider then \textwidth which is the width of the text body on the page.

\documentclass{article}
\usepackage[margin=2cm]{geometry}
\usepackage[dvipsnames,table]{xcolor}
\definecolor{light-gray}{HTML}{FFFFFF}
\definecolor{light-blue}{HTML}{EBF5FB}
\usepackage{tabularray}

\begin{document}

    {\centering Centered Text\par}
    
    \begin{longtblr}[
        caption = {This is a caption.},
        ]{
            colspec={m{1.2cm} m{0.5cm} m{1cm} m{1cm} m{1.5cm} m{3.5cm} m{1.5cm}},
            cells={font=\small},
            row{1}={font=\itshape\small},
            row{2,5-7}={bg=light-blue},
            row{3-4}={bg=light-gray},
            hlines
        }
        & Day
        & Month
        & Hours
        & Feature 1 
        & Feature 2
        & Feature 3\\
        %-------------------------------------------------
        Friday
        & 5 
        & June
        & 
        & A\textsubscript{1}
        & % A\textsubscript{2}
        \begin{tblr}{ |c|c|c| }
            \hline
             cell1 & cell2 & cell3 \\ 
             cell4 & cell5 & cell6 \\ 
             cell7 & cell8 & cell9 \\ 
             \hline
        \end{tblr}
        & A\textsubscript{3}
        \\
        %-------------------------------------------------
        \SetCell[r=2]{l} Saturday 
        & \SetCell[r=2]{l} 6 
        & \SetCell[r=2]{l} June
        & 14 -- 21
        & B\textsubscript{1}
        &
        & B\textsubscript{3}
        \\
        &  
        & 
        &
        & C\textsubscript{1}
        & C\textsubscript{2}
        & C\textsubscript{3}
        \\
        % -------------------------------------------------
        \SetCell[r=3]{l} Sunday
        & \SetCell[r=3]{l} 7
        & \SetCell[r=3]{l} June
        & 08 -- 10
        & D\textsubscript{1}
        & D\textsubscript{2}
        & D\textsubscript{3}
        \\
        & 
        &
        & 10 -- 17
        & E\textsubscript{1}
        &
        & E\textsubscript{3}
        \\
        & 
        & 
        & 
        & F\textsubscript{1}
        & F\textsubscript{2}
        & F\textsubscript{3}
        \\
        % -------------------------------------------------
    \end{longtblr}
    
\end{document}

enter image description here


I am unsure what you want to place in the cells, but it might be a solution (albeit probably not the best one) to harden the relevant cells using a minipage, so you can place whatever you want inside. Since I take it that all cells in column six should behave the same way, I used suitable options to make future coding easier:

\documentclass{article}
\usepackage[margin=2cm]{geometry}
\usepackage[dvipsnames,table]{xcolor}
\definecolor{light-gray}{HTML}{FFFFFF}
\definecolor{light-blue}{HTML}{EBF5FB}
\usepackage{tabularray}

\begin{document}

    {\centering Centered Text\par}
    
    \begin{longtblr}[
        caption = {This is a caption.},
        ]{
            colspec={m{1.2cm} m{0.5cm} m{1cm} m{1cm} m{1.5cm} m{3.5cm} m{1.5cm}},
            cells={font=\small},
            row{1}={font=\itshape\small},
            row{2,5-7}={bg=light-blue},
            row{3-4}={bg=light-gray},
            column{6}={preto={\begin{minipage}{3.5cm}}, appto={\end{minipage}}},
            hlines
        }
        & Day
        & Month
        & Hours
        & Feature 1 
        & Feature 2
        & Feature 3\\
        %-------------------------------------------------
        Friday
        & 5 
        & June
        & 
        & A\textsubscript{1}
        & This is a long text that will be repeated many times. This is a long text that will be repeated many times. This is a long text that will be repeated many times. This is a long text that will be repeated many times. This is a long text that will be repeated many times. This is a long text that will be repeated many times. This is a long text that will be repeated many times. This is a long text that will be repeated many times. This is a long text that will be repeated many times. 
        \begin{tblr}{ |c|c|c| }
            \hline
             cell1 & cell2 & cell3 \\ 
             cell4 & cell5 & cell6 \\ 
             cell7 & cell8 & cell9 \\ 
             \hline
        \end{tblr}
        This is a long text that will be repeated many times. This is a long text that will be repeated many times. This is a long text that will be repeated many times. 
        & A\textsubscript{3}
        \\
        %-------------------------------------------------
        \SetCell[r=2]{l} Saturday 
        & \SetCell[r=2]{l} 6 
        & \SetCell[r=2]{l} June
        & 14 -- 21
        & B\textsubscript{1}
        &
        & B\textsubscript{3}
        \\
        &  
        & 
        &
        & C\textsubscript{1}
        & C\textsubscript{2}
        & C\textsubscript{3}
        \\
        % -------------------------------------------------
        \SetCell[r=3]{l} Sunday
        & \SetCell[r=3]{l} 7
        & \SetCell[r=3]{l} June
        & 08 -- 10
        & D\textsubscript{1}
        & D\textsubscript{2}
        & D\textsubscript{3}
        \\
        & 
        &
        & 10 -- 17
        & E\textsubscript{1}
        &
        & E\textsubscript{3}
        \\
        & 
        & 
        & 
        & F\textsubscript{1}
        & F\textsubscript{2}
        & F\textsubscript{3}
        \\
        % -------------------------------------------------
    \end{longtblr}
    
\end{document}

enter image description here


In case your editor complains about the syntax (which is, in fact, not wrong as you will see if you try to compile the code), you can replace

column{6}={preto={\begin{minipage}{3.5cm}}, appto={\end{minipage}}},

by

column{6}={preto={\minipage{3.5cm}}, appto={\endminipage}},

which should calm down the editor's syntax validation mechanism.

5
  • A great answer!!! Many thanks for your explanation!! :-) I am very grateful @Jasper Habich :-)
    – Ommo
    Feb 28, 2023 at 17:12
  • Hello @Jasper Habicht, I think there is a small issue about formatting with your solution, by using the tblr environment... Please see my edited question... Is there anything I can do there ?
    – Ommo
    Feb 28, 2023 at 17:52
  • Perfect! Your edited answer works perfectly!! I just get some sort of red-coloured warnings in my editor: closed \begin{minipage} found at close group } unexpected close group } after \begin{minipage} unexpected \end{minipage} after \begin{longtblr} unclosed open group { found at \end{minipage} unclosed open group { found at \end{minipage}
    – Ommo
    Feb 28, 2023 at 19:05
  • 1
    @limone This warning is because the editor thinks that the syntax is wrong. But it is, in fact, not wrong. You can ignore these syntax warnings. Upon compilation, no errors should be output by LaTeX itself. If you find these syntax warnings too annoying, you can replace \begin{minipage}{3.5cm} by \minipage{3.5cm} and \end{minipage} by \endminipage. Feb 28, 2023 at 19:26
  • Ok, great, I will ignore them :-) The output (after the compilation) is perfect, i.e. without any errors or warnings.. Again, I am very grateful!
    – Ommo
    Feb 28, 2023 at 19:28

You must log in to answer this question.

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