3

This is my first question here. I read many topics, but none have solved my problem.

I need to split a table (using longtable or other) with the tabularx settings. I tried ltablex, but this changed all the other tables in the text. I also tried LTXtable, but I guess I did not know how to use it properly.

Below is the code and appearance using tabularx, as I want it to stay using longtable.

\documentclass{article}
\usepackage{booktabs}
\usepackage{tabularx}
\usepackage{array}
\usepackage{float}
\begin{document}
\begin{table}[H]
    \centering
    \small
    \caption{Planejamento experimental.}
    \label{tab:MatrizPlanExp}
    \newcolumntype{C}{>{\centering\arraybackslash\hsize=1\hsize}X}
    \renewcommand{\arraystretch}{1.15} % Espaçamento
    \begin{tabularx}{\textwidth}{CCC}
        \toprule
        \textbf{Experimento nº} & \textbf{Temperatura (°C)} & \textbf{WHSV (h$^{-1}$)} \\
        \midrule
        1     & 240   & 40 \\
        2     & 240   & 45 \\
        3     & 240   & 50 \\
        4     & 240   & 55 \\
        5     & 240   & 60 \\
        6     & 260   & 40 \\
        7     & 260   & 45 \\
        8     & 260   & 50 \\
        9     & 260   & 55 \\
        10    & 260   & 60 \\
        11    & 280   & 40 \\
        12    & 280   & 45 \\
        13    & 280   & 50 \\
        14    & 280   & 50 \\
        15    & 280   & 50 \\
        16    & 280   & 55 \\
        17    & 280   & 60 \\
        18    & 300   & 5 \\
        19    & 300   & 10 \\
        20    & 300   & 20 \\
        21    & 320   & 2,5 \\
        22    & 320   & 5 \\
        23    & 320   & 10 \\
        24    & 320   & 20 \\
        25    & 340   & 2,5 \\
        26    & 340   & 5 \\
        27    & 340   & 10 \\
        28    & 340   & 20 \\
        \bottomrule
    \end{tabularx}
\end{table}
\end{document}

enter image description here

Here is the best I got using longtable (I have increased the lines to go to the other page).

\begin{document}
\begin{longtable}{@{}P{4cm}P{4cm}P{4cm}@{}}
    \caption{Planejamento experimental.}\\
    \toprule
    \textbf{Experimento nº} & \textbf{Temperatura (°C)} & \textbf{WHSV (h$^{-1}$)} \\
    \midrule
    1     & 240   & 40 \\
    2     & 240   & 45 \\
    3     & 240   & 50 \\
    4     & 240   & 55 \\
    5     & 240   & 60 \\
    6     & 260   & 40 \\
    7     & 260   & 45 \\
    8     & 260   & 50 \\
    9     & 260   & 55 \\
    10    & 260   & 60 \\
    11    & 280   & 40 \\
    12    & 280   & 45 \\
    13    & 280   & 50 \\
    14    & 280   & 50 \\
    15    & 280   & 50 \\
    16    & 280   & 55 \\
    17    & 280   & 60 \\
    18    & 300   & 5 \\
    19    & 300   & 10 \\
    20    & 300   & 20 \\
    21    & 320   & 2,5 \\
    22    & 320   & 5 \\
    23    & 320   & 10 \\
    24    & 320   & 20 \\
    25    & 340   & 2,5 \\
    26    & 340   & 5 \\
    27    & 340   & 10 \\
    28    & 340   & 20 \\
    19    & 300   & 10 \\
    20    & 300   & 20 \\
    21    & 320   & 2,5 \\
    22    & 320   & 5 \\
    23    & 320   & 10 \\
    24    & 320   & 20 \\
    25    & 340   & 2,5 \\
    26    & 340   & 5 \\
    27    & 340   & 10 \\
    28    & 340   & 20 \\
    20    & 300   & 20 \\
    21    & 320   & 2,5 \\
    22    & 320   & 5 \\
    23    & 320   & 10 \\
    24    & 320   & 20 \\
    25    & 340   & 2,5 \\
    26    & 340   & 5 \\
    27    & 340   & 10 \\
    \bottomrule
    \label{tab:MatrizPlanExp}\\
\end{longtable}
\end{document}

enter image description here

I would like to:

1) Use \small font with longtable without decreasing the font of the caption.

2) Have a row closing and starting the split table.

3) Write on the dividing page that the table continues on the next page, or something like that.

Please, help me.

6
  • 2
    We'lcome to TeX SX! What do you mean with ‘ltablex changed all other tables’?
    – Bernard
    Commented Mar 18, 2018 at 23:40
  • You did remove the table wrapper, right? You can't have a float split across pages, so you need to get rid of that.
    – cfr
    Commented Mar 19, 2018 at 2:40
  • I would never use tabularx for such a table, tabularx is designed to control line breaking within the table cells and you have no linebreaking in these kinds of data tables, so the only effect of forcing the table to be \textwidth wide is that the columns are further apart so the table is harder to read. Commented Mar 19, 2018 at 7:56
  • Bernard, with "ltablex changed all other tables" I meant that this command changed the formatting of all the other tables in my dissertation (another 20), which I configured individually.
    – Mellyssa
    Commented Mar 21, 2018 at 23:03
  • Crf, yes, I removed "table". Still, it was not what I wanted. Thanks.
    – Mellyssa
    Commented Mar 21, 2018 at 23:04

2 Answers 2

1

Are you trying to do something like this?

\documentclass[12pt]{article}
\usepackage{longtable}
\begin{document}
    \begin{small}
        \begin{longtable}{ p{4cm} p{4cm} p{4cm} }
            \caption{Planejamento experimental.} \\
            \hline
            \multicolumn{1}{c}{\textbf{Experimento nº}} & \multicolumn{1}{c}{\textbf{Temperatura (°C)}} & \multicolumn{1}{c}{\textbf{WHSV (h$^{-1}$)}} \\
            \hline
            \endfirsthead
            \multicolumn{3}{c}
            {\tablename\ \thetable\ -- \textit{Continued from previous page}} \\
            \hline
            \multicolumn{1}{c}{\textbf{Experimento nº}} & \multicolumn{1}{c}{\textbf{Temperatura (°C)}} & \multicolumn{1}{c}{\textbf{WHSV (h$^{-1}$)}} \\
            \hline
            \endhead
            \hline \multicolumn{3}{r}{\textit{Continued on next page}} \\
            \endfoot
            \hline
            \endlastfoot
            \multicolumn{1}{c}{1}     & \multicolumn{1}{c}{240}   & \multicolumn{1}{c}{40} \\
            \multicolumn{1}{c}{2}     & \multicolumn{1}{c}{240}   & \multicolumn{1}{c}{45} \\
            \multicolumn{1}{c}{3}     & \multicolumn{1}{c}{240}   & \multicolumn{1}{c}{50} \\
            \multicolumn{1}{c}{4}     & \multicolumn{1}{c}{240}   & \multicolumn{1}{c}{55} \\
            \multicolumn{1}{c}{5}     & \multicolumn{1}{c}{240}   & \multicolumn{1}{c}{60} \\
            \multicolumn{1}{c}{6}     & \multicolumn{1}{c}{260}   & \multicolumn{1}{c}{40} \\
            \multicolumn{1}{c}{7}     & \multicolumn{1}{c}{260}   & \multicolumn{1}{c}{45} \\
            \multicolumn{1}{c}{8}     & \multicolumn{1}{c}{260}   & \multicolumn{1}{c}{50} \\
            \multicolumn{1}{c}{9}     & \multicolumn{1}{c}{260}   & \multicolumn{1}{c}{55} \\
            \multicolumn{1}{c}{10}    & \multicolumn{1}{c}{260}   & \multicolumn{1}{c}{60} \\
            \multicolumn{1}{c}{11}    & \multicolumn{1}{c}{280}   & \multicolumn{1}{c}{40} \\
            \multicolumn{1}{c}{12}    & \multicolumn{1}{c}{280}   & \multicolumn{1}{c}{45} \\
            \multicolumn{1}{c}{13}    & \multicolumn{1}{c}{280}   & \multicolumn{1}{c}{50} \\
            \multicolumn{1}{c}{14}    & \multicolumn{1}{c}{280}   & \multicolumn{1}{c}{50} \\
            \multicolumn{1}{c}{15}    & \multicolumn{1}{c}{280}   & \multicolumn{1}{c}{50} \\
            \multicolumn{1}{c}{16}    & \multicolumn{1}{c}{280}   & \multicolumn{1}{c}{55} \\
            \multicolumn{1}{c}{17}    & \multicolumn{1}{c}{280}   & \multicolumn{1}{c}{60} \\
            \multicolumn{1}{c}{18}    & \multicolumn{1}{c}{300}   & \multicolumn{1}{c}{5 }\\
            \multicolumn{1}{c}{19}    & \multicolumn{1}{c}{300}   & \multicolumn{1}{c}{10} \\
            \multicolumn{1}{c}{20}    & \multicolumn{1}{c}{300}   & \multicolumn{1}{c}{20} \\
            \multicolumn{1}{c}{21}    & \multicolumn{1}{c}{320}   & \multicolumn{1}{c}{2,5} \\
            \multicolumn{1}{c}{22}    & \multicolumn{1}{c}{320}   & \multicolumn{1}{c}{5} \\
            \multicolumn{1}{c}{23}    & \multicolumn{1}{c}{320}   & \multicolumn{1}{c}{10} \\
            \multicolumn{1}{c}{24}    & \multicolumn{1}{c}{320}   & \multicolumn{1}{c}{20} \\
            \multicolumn{1}{c}{25}    & \multicolumn{1}{c}{340}   & \multicolumn{1}{c}{2,5} \\
            \multicolumn{1}{c}{26}    & \multicolumn{1}{c}{340}   & \multicolumn{1}{c}{5} \\
            \multicolumn{1}{c}{27}    & \multicolumn{1}{c}{340}   & \multicolumn{1}{c}{10} \\
            \multicolumn{1}{c}{28}    & \multicolumn{1}{c}{340}   & \multicolumn{1}{c}{20} \\
            \multicolumn{1}{c}{19}    & \multicolumn{1}{c}{300}   & \multicolumn{1}{c}{10} \\
            \multicolumn{1}{c}{20}    & \multicolumn{1}{c}{300}   & \multicolumn{1}{c}{20} \\
            \multicolumn{1}{c}{21}    & \multicolumn{1}{c}{320}   & \multicolumn{1}{c}{2,5} \\
            \multicolumn{1}{c}{22}    & \multicolumn{1}{c}{320}   & \multicolumn{1}{c}{5} \\
            \multicolumn{1}{c}{23}    & \multicolumn{1}{c}{320}   & \multicolumn{1}{c}{10} \\
            \multicolumn{1}{c}{24}    & \multicolumn{1}{c}{320}   & \multicolumn{1}{c}{20} \\
            \multicolumn{1}{c}{25}    & \multicolumn{1}{c}{340}   & \multicolumn{1}{c}{2,5} \\
            \multicolumn{1}{c}{26}    & \multicolumn{1}{c}{340}   & \multicolumn{1}{c}{5} \\
            \multicolumn{1}{c}{27}    & \multicolumn{1}{c}{340}   & \multicolumn{1}{c}{10} \\
            \multicolumn{1}{c}{28}    & \multicolumn{1}{c}{340}   & \multicolumn{1}{c}{20} \\
            \multicolumn{1}{c}{20}    & \multicolumn{1}{c}{300}   & \multicolumn{1}{c}{20} \\
            \multicolumn{1}{c}{21}    & \multicolumn{1}{c}{320}   & \multicolumn{1}{c}{2,5} \\
            \multicolumn{1}{c}{22}    & \multicolumn{1}{c}{320}   & \multicolumn{1}{c}{5} \\
            \multicolumn{1}{c}{23}    & \multicolumn{1}{c}{320}   & \multicolumn{1}{c}{10} \\
            \multicolumn{1}{c}{24}    & \multicolumn{1}{c}{320}   & \multicolumn{1}{c}{20} \\
            \multicolumn{1}{c}{25}    & \multicolumn{1}{c}{340}   & \multicolumn{1}{c}{2,5} \\
            \multicolumn{1}{c}{26}    & \multicolumn{1}{c}{340}   & \multicolumn{1}{c}{5} \\
            \multicolumn{1}{c}{27}    & \multicolumn{1}{c}{340}   & \multicolumn{1}{c}{10} \\
        \end{longtable}
    \end{small}
\end{document}
3
  • I tried various means to eliminate or minimize the redundant multicolumn commands to center the fields under each column, but unfortunately, nothing seemed to work with the longtable other than the multicolumn{1} for each cell. Trying to do a multicolumn{3} doesn't work. I'm new at LaTeX myself and thought I'd tackle your question for my own learning. Commented Mar 19, 2018 at 3:41
  • Yeah, that's how I wanted it to go. Thank you.
    – Mellyssa
    Commented Mar 21, 2018 at 22:58
  • 1
    Far simple is remove all \multicolumn and intesat them redfined table specification to \begin{longtable}{ *{3}{>{\centering\arraybackslash}p{4cm} }.
    – Zarko
    Commented Aug 16, 2021 at 14:34
6

After three years ... this table can be write with powerful new table package tabularray. For better aligning numbers in columns I would employ siunitx package (loaded as tabularray library):

\documentclass[12pt]{article}
\usepackage{tabularray}
\UseTblrLibrary{booktabs,siunitx}
 
\begin{document}

    \begin{longtblr}[caption = {Planejamento experimental.}
                    ]%
                    {colspec={*{3}{ X[c,si]} },
                     rowhead = {1},
                     rows = {font=\small}
                    }
    \toprule
\mbox{Experimento nº}
    &  \mbox{Temperatura (\si{\celsius})}
            &  \mbox{WH{S}V (h$^{-1}$)}
                    \\
    \midrule
 1  & 240   & 40    \\
 2  & 240   & 45    \\
 3  & 240   & 50    \\
 4  & 240   & 55    \\
 5  & 240   & 60    \\
 6  & 260   & 40    \\
 7  & 45    & 45    \\
 8  & 260   & 50    \\
 9  & 260   & 55    \\
10  & 260   & 60    \\
11  & 280   & 40    \\
12  & 280   & 45    \\
13  & 280   & 50    \\
14  & 280   & 50    \\
15  & 280   & 50    \\
16  & 280   & 55    \\
17  & 280   & 60    \\
18  & 300   &  5    \\
19  & 300   & 10    \\
20  & 300   & 20    \\
21  & 320   &  2.5  \\
22  & 320   &  5    \\
23  & 320   & 10    \\
24  & 320   & 20    \\
25  & 340   &  2.5  \\
26  & 340   &  5    \\
27  & 340   & 10    \\
28  & 340   & 20    \\
19  & 300   & 10    \\
20  & 300   & 20    \\
21  & 320   &  2.5  \\
22  & 320   &  5    \\
23  & 320   & 10    \\
24  & 320   & 20    \\
25  & 340   &  2.5  \\
26  & 340   &  5    \\
27  & 340   & 10    \\
28  & 340   & 20    \\
20  & 300   & 20    \\
21  & 320   &  2.5  \\
22  & 320   &  5    \\
23  & 320   & 10    \\
24  & 320   & 20    \\
25  & 340   &  2.5  \\
26  & 340   &  5    \\
27  & 340   & 10    \\
    \bottomrule
    \end{longtblr}
\end{document}

enter image description here

Edit: Instead of

\mbox{Experimento nº}
    &  \mbox{Temperatura (\si{\celsius})}
            &  \mbox{WH{S}V (h$^{-1}$)}
                    \\

can be used

{{{Experimento nº}}}
    &  {{{Temperatura (\si{\celsius})}}}
            &  {{{WH{S}V (h$^{-1}$)}}}
                    \\

Result is the same as before, but with it the table code is more in tabularray spirit :-)

3
  • In version 2022B of tabularray to be released on June 1st, you will be able to write row{1}={guard} instead of three pairs of curly braces.
    – L.J.R.
    Commented May 20, 2022 at 9:58
  • @L.J.R. super! This will significantly simplify writing table with S (\si) columns. BTW, I'm curious, do you know when Overleaf will upgrade its installation of the tabularray package? I sow here many people, who use Overleaf` that they like to use `tabularray with functionality at least of version 2021N or newest.
    – Zarko
    Commented May 20, 2022 at 10:17
  • Overleaf updated TeXlive 2020 and 2021 in October. So I guess they will update TeXlive 2022 in similar time.
    – L.J.R.
    Commented May 20, 2022 at 10:38

You must log in to answer this question.

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