带有 tabularx 设置的 Longtable

带有 tabularx 设置的 Longtable

这是我在这里的第一个问题。我读了很多主题,但没有一个能解决我的问题。

我需要使用设置拆分表格(使用longtable或其他)tabularx。我尝试过ltablex,但这会更改文本中的所有其他表格。我也尝试过LTXtable,但我想我不知道如何正确使用它。

下面是使用的代码和外观tabularx,因为我希望它继续使用 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}

在此处输入图片描述

这是我使用过的最好的方法longtable(我增加了转到其他页面的行数)。

\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}

在此处输入图片描述

我想:

1)使用\small字体,但longtable不减小标题的字体。

2) 有一行结束并开始分割表。

3)在分隔页上写上表格在下一页继续,或类似内容。

请帮我。

答案1

你想做这样的事吗?

\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}

答案2

三年后...可以使用功能强大的新表格包来编写此表格tabularray。为了更好地对齐列中的数字,我将使用siunitx包(作为tabularray库加载):

\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}

在此处输入图片描述

编辑: 代替

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

可以使用

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

结果与以前相同,但表格代码更符合tabularray精神:-)

相关内容