长表多行问题

长表多行问题

我已经尝试了一整天来解决这个问题,但我无法让它发挥作用。

我的长表的表头与多行列名重叠。有人能帮我看看我做错了什么吗?

(大部分代码都是从我的 Python 笔记本中导出的,但我就是不知道如何在 Python 或 Latex 中正确包装标题。)

\begin{longtable}{SSSSSS}
\caption{Number and Percent of Family and Nonfamily Firms by Two-Digit SIC} \label{Table I:} \\

{\multirow{3}{1cm}{SIC}} & 
{\multirow{3}{2cm}{Nonfamily Firms}} & 
{\multirow{3}{2cm}{FamFirm}} & 
{\multirow{4}{2cm}{Percent Family Firms in Industry}} & 
{\multirow{4}{2cm}{Percent Founder CEO Firms in Industry}} & 
{\multirow{3}{2cm}{Percent Non-Founder Firms in Industry}} 
\\

\endfirsthead

\caption[]{Number and Percent of Family and Nonfamily Firms by Two-Digit SIC} \\
{\multirow{3}{1cm}{SIC}} & 
{\multirow{3}{2cm}{Nonfamily Firms}} & 
{\multirow{3}{2cm}{FamFirm}} & 
{\multirow{3}{2cm}{Percent Family Firms in Industry}} & 
{\multirow{3}{2cm}{Percent Founder CEO Firms in Industry}} & 
{\multirow{3}{2cm}{Percent Non-Founder Firms in Industry}} \\

\endhead
\multicolumn{6}{r}{Continued on next page} \\
\endfoot
\endlastfoot

10 & 16 & 0 & 0.000000 & 0.000000 & 0.000000 \\
13 & 44 & 0 & 0.000000 & 0.000000 & 0.000000 \\
15 & 7 & 4 & 36.400000 & 0.000000 & 36.400000 \\
16 & 15 & 0 & 0.000000 & 0.000000 & 0.000000 \\
20 & 54 & 58 & 51.800000 & 0.000000 & 51.800000 \\
21 & 9 & 0 & 0.000000 & 0.000000 & 0.000000 \\
22 & 0 & 10 & 100.000000 & 0.000000 & 100.000000 \\
23 & 8 & 8 & 50.000000 & 18.800000 & 50.000000 \\
24 & 9 & 10 & 52.600000 & 0.000000 & 52.600000 \\
25 & 8 & 0 & 0.000000 & 0.000000 & 0.000000 \\
26 & 49 & 24 & 32.900000 & 4.100000 & 32.900000 \\
27 & 27 & 55 & 67.100000 & 0.000000 & 67.100000 \\
28 & 149 & 57 & 27.700000 & 0.000000 & 27.700000 \\
29 & 57 & 11 & 16.200000 & 4.400000 & 11.800000 \\
30 & 25 & 26 & 51.000000 & 29.400000 & 21.600000 \\
31 & 9 & 0 & 0.000000 & 0.000000 & 0.000000 \\
32 & 7 & 0 & 0.000000 & 0.000000 & 0.000000 \\
33 & 57 & 25 & 30.500000 & 8.500000 & 22.000000 \\
34 & 35 & 18 & 34.000000 & 0.000000 & 34.000000 \\
35 & 92 & 55 & 37.400000 & 6.800000 & 30.600000 \\
36 & 77 & 29 & 27.400000 & 13.200000 & 14.200000 \\
37 & 87 & 41 & 32.000000 & 3.900000 & 28.100000 \\
38 & 67 & 19 & 22.100000 & 15.100000 & 7.000000 \\
39 & 14 & 8 & 36.400000 & 0.000000 & 36.400000 \\
40 & 32 & 0 & 0.000000 & 0.000000 & 0.000000 \\
42 & 2 & 5 & 71.400000 & 0.000000 & 71.400000 \\
45 & 34 & 7 & 17.100000 & 17.100000 & 0.000000 \\
48 & 23 & 16 & 41.000000 & 17.900000 & 23.100000 \\
49 & 8 & 4 & 33.300000 & 33.300000 & 0.000000 \\
50 & 20 & 8 & 28.600000 & 0.000000 & 28.600000 \\
51 & 41 & 2 & 4.700000 & 0.000000 & 4.700000 \\
52 & 14 & 7 & 33.300000 & 33.300000 & 0.000000 \\
53 & 38 & 19 & 33.300000 & 8.800000 & 24.600000 \\
54 & 9 & 25 & 73.500000 & 0.000000 & 73.500000 \\
55 & 0 & 7 & 100.000000 & 0.000000 & 100.000000 \\
56 & 15 & 28 & 65.100000 & 32.600000 & 32.600000 \\
57 & 15 & 0 & 0.000000 & 0.000000 & 0.000000 \\
58 & 7 & 5 & 41.700000 & 0.000000 & 41.700000 \\
59 & 14 & 20 & 58.800000 & 11.800000 & 52.900000 \\
60 & 0 & 8 & 100.000000 & 0.000000 & 100.000000 \\
61 & 21 & 0 & 0.000000 & 0.000000 & 0.000000 \\
62 & 8 & 0 & 0.000000 & 0.000000 & 0.000000 \\
63 & 87 & 20 & 18.700000 & 3.700000 & 15.000000 \\
64 & 9 & 0 & 0.000000 & 0.000000 & 0.000000 \\
70 & 0 & 14 & 100.000000 & 0.000000 & 100.000000 \\
72 & 0 & 17 & 100.000000 & 41.200000 & 58.800000 \\
73 & 43 & 24 & 35.800000 & 26.900000 & 9.000000 \\
75 & 8 & 0 & 0.000000 & 0.000000 & 0.000000 \\
78 & 10 & 6 & 37.500000 & 0.000000 & 37.500000 \\
79 & 12 & 0 & 0.000000 & 0.000000 & 0.000000 \\
80 & 12 & 0 & 0.000000 & 0.000000 & 0.000000 \\
87 & 7 & 0 & 0.000000 & 0.000000 & 0.000000 \\
99 & 19 & 0 & 0.000000 & 0.000000 & 0.000000 \\
\end{longtable}

答案1

一些建议:

  • 我建议您使用xltabular包及其同名环境,而不是longtable环境。这样,您可以在标题单元格中设置自动换行。基本上,环境结合了和环境xltabular的功能。longtabletabularx

  • 我会将最后 3 个数据列中的数字四舍五入为仅保留 1 位有效小数。使用siunitx包及其S列类型可以轻松实现此操作。

  • 使用包的宏booktabs来绘制间距适当的水平线。

以下屏幕截图显示了生成的双页表的第一页的开头。

在此处输入图片描述

\documentclass{article}
\usepackage{geometry} % set page parameters appropriately
\usepackage{xltabular,ragged2e,siunitx,booktabs}
\newcolumntype{C}{>{\Centering}X}
% handy shortcut macro:
\newcommand{\mC}[2]{\multicolumn{1}{>{\hsize=#1\hsize}C}{#2}}
\newcolumntype{T}[1]{S[table-format=#1]}

\begin{document}

\begingroup % localize scope of next two instructions:
\setlength{\LTcapwidth}{\textwidth}
\setlength\tabcolsep{3pt} % default: 6pt
\begin{xltabular}{\textwidth}{@{} c T{3} T{2} 
      *{3}{T{3.1,round-mode=places,round-precision=1}} @{}}

\caption{Number and Percent of Family and Nonfamily Firms, by Two-Digit SIC} \label{Table_I} \\
\toprule
SIC & \mC{0.7}{Nonfamily Firms} & \mC{0.5}{Family Firms} & 
\mC{1.2}{Percent Family Firms in Industry} & 
\mC{1.3}{Percent Founder CEO Firms in Industry} & 
\mC{1.3}{Percent Non-Founder Firms in Industry} \\
\midrule
\endfirsthead

\multicolumn{6}{@{}l}{Table \thetable, cont'd}\\[1ex]
\toprule
SIC & \mC{0.7}{Nonfamily Firms} & \mC{0.5}{Family Firms} & 
\mC{1.2}{Percent Family Firms in Industry} & 
\mC{1.3}{Percent Founder CEO Firms in Industry} & 
\mC{1.3}{Percent Non-Founder Firms in Industry} \\
\midrule
\endhead

\midrule
\multicolumn{6}{r@{}}{(Continued on next page)} \\
\endfoot

\bottomrule
\endlastfoot

10 & 16 & 0 & 0.000000 & 0.000000 & 0.000000 \\
13 & 44 & 0 & 0.000000 & 0.000000 & 0.000000 \\
15 & 7 & 4 & 36.400000 & 0.000000 & 36.400000 \\
16 & 15 & 0 & 0.000000 & 0.000000 & 0.000000 \\
20 & 54 & 58 & 51.800000 & 0.000000 & 51.800000 \\
21 & 9 & 0 & 0.000000 & 0.000000 & 0.000000 \\
22 & 0 & 10 & 100.000000 & 0.000000 & 100.000000 \\
23 & 8 & 8 & 50.000000 & 18.800000 & 50.000000 \\
24 & 9 & 10 & 52.600000 & 0.000000 & 52.600000 \\
25 & 8 & 0 & 0.000000 & 0.000000 & 0.000000 \\
26 & 49 & 24 & 32.900000 & 4.100000 & 32.900000 \\
27 & 27 & 55 & 67.100000 & 0.000000 & 67.100000 \\
28 & 149 & 57 & 27.700000 & 0.000000 & 27.700000 \\
29 & 57 & 11 & 16.200000 & 4.400000 & 11.800000 \\
30 & 25 & 26 & 51.000000 & 29.400000 & 21.600000 \\
31 & 9 & 0 & 0.000000 & 0.000000 & 0.000000 \\
32 & 7 & 0 & 0.000000 & 0.000000 & 0.000000 \\
33 & 57 & 25 & 30.500000 & 8.500000 & 22.000000 \\
34 & 35 & 18 & 34.000000 & 0.000000 & 34.000000 \\
35 & 92 & 55 & 37.400000 & 6.800000 & 30.600000 \\
36 & 77 & 29 & 27.400000 & 13.200000 & 14.200000 \\
37 & 87 & 41 & 32.000000 & 3.900000 & 28.100000 \\
38 & 67 & 19 & 22.100000 & 15.100000 & 7.000000 \\
39 & 14 & 8 & 36.400000 & 0.000000 & 36.400000 \\
40 & 32 & 0 & 0.000000 & 0.000000 & 0.000000 \\
42 & 2 & 5 & 71.400000 & 0.000000 & 71.400000 \\
45 & 34 & 7 & 17.100000 & 17.100000 & 0.000000 \\
48 & 23 & 16 & 41.000000 & 17.900000 & 23.100000 \\
49 & 8 & 4 & 33.300000 & 33.300000 & 0.000000 \\
50 & 20 & 8 & 28.600000 & 0.000000 & 28.600000 \\
51 & 41 & 2 & 4.700000 & 0.000000 & 4.700000 \\
52 & 14 & 7 & 33.300000 & 33.300000 & 0.000000 \\
53 & 38 & 19 & 33.300000 & 8.800000 & 24.600000 \\
54 & 9 & 25 & 73.500000 & 0.000000 & 73.500000 \\
55 & 0 & 7 & 100.000000 & 0.000000 & 100.000000 \\
56 & 15 & 28 & 65.100000 & 32.600000 & 32.600000 \\
57 & 15 & 0 & 0.000000 & 0.000000 & 0.000000 \\
58 & 7 & 5 & 41.700000 & 0.000000 & 41.700000 \\
59 & 14 & 20 & 58.800000 & 11.800000 & 52.900000 \\
60 & 0 & 8 & 100.000000 & 0.000000 & 100.000000 \\
61 & 21 & 0 & 0.000000 & 0.000000 & 0.000000 \\
62 & 8 & 0 & 0.000000 & 0.000000 & 0.000000 \\
63 & 87 & 20 & 18.700000 & 3.700000 & 15.000000 \\
64 & 9 & 0 & 0.000000 & 0.000000 & 0.000000 \\
70 & 0 & 14 & 100.000000 & 0.000000 & 100.000000 \\
72 & 0 & 17 & 100.000000 & 41.200000 & 58.800000 \\
73 & 43 & 24 & 35.800000 & 26.900000 & 9.000000 \\
75 & 8 & 0 & 0.000000 & 0.000000 & 0.000000 \\
78 & 10 & 6 & 37.500000 & 0.000000 & 37.500000 \\
79 & 12 & 0 & 0.000000 & 0.000000 & 0.000000 \\
80 & 12 & 0 & 0.000000 & 0.000000 & 0.000000 \\
87 & 7 & 0 & 0.000000 & 0.000000 & 0.000000 \\
99 & 19 & 0 & 0.000000 & 0.000000 & 0.000000 \\
\end{xltabular}
\endgroup

\end{document}

答案2

在包longtblr中定义`tabularray

\documentclass{article}
\usepackage{geometry} 
\usepackage{tabularray}
\UseTblrLibrary{booktabs, siunitx}
\NewTableCommand\mc{\SetCell{c}}
  \ExplSyntaxOn
\NewChildSelector{eachfive}
  {
    \int_step_inline:nnnn {6}{5}{\l_tblr_childs_total_tl}
      { \clist_put_right:Nn \l_tblr_childs_clist {##1} }
  }
\ExplSyntaxOff

\begin{document}

\begin{longtblr}[
caption = {Number and Percent of Family and Nonfamily Firms, 
           by Two-Digit SIC},
  label = {Table_I}
                ]{ colsep = 4pt,
                  colspec = {@{} c
                            *{2}{X[1, c, si={table-format=3.0}]}
                            *{3}{X[2, c, si={table-format=3.2,
                                          round-mode=places,
                                          round-precision=2}]}
                            @{}},
                 row{2-Z} = {rowsep = 0pt},
                   row{1} = {font=\small, m},
            row{eachfive} = {abovesep=1ex},
                  rowhead = 1
                  }
    \toprule
SIC & \mc   {{{Nonfamily Firms}}}
    & \mc   {{{Family Firms}}}
    & \mc   {{{Percent Family\\ Firms in Industry}}}
    & \mc   {{{Percent Founder CEO Firms in Industry}}}
    & \mc   {{{Percent Non-Founder Firms in Industry}}} \\
    \midrule
10 &  16    &  0 &   0.000000 &  0.000000 &   0.000000 \\
13 &  44    &  0 &   0.000000 &  0.000000 &   0.000000 \\
15 &   7    &  4 &  36.400000 &  0.000000 &  36.400000 \\
16 &  15    &  0 &   0.000000 &  0.000000 &   0.000000 \\
20 &  54    & 58 &  51.800000 &  0.000000 &  51.800000 \\
21 &   9    &  0 &   0.000000 &  0.000000 &   0.000000 \\
22 &   0    & 10 & 100.000000 &  0.000000 & 100.000000 \\
23 &   8    &  8 &  50.000000 & 18.800000 &  50.000000 \\
24 &   9    & 10 &  52.600000 &  0.000000 &  52.600000 \\
25 &   8    &  0 &   0.000000 &  0.000000 &   0.000000 \\
26 &  49    & 24 &  32.900000 &  4.100000 &  32.900000 \\
27 &  27    & 55 &  67.100000 &  0.000000 &  67.100000 \\
28 & 149    & 57 &  27.700000 &  0.000000 &  27.700000 \\
29 &  57    & 11 &  16.200000 &  4.400000 &  11.800000 \\
30 &  25    & 26 &  51.000000 & 29.400000 &  21.600000 \\
31 &   9    &  0 &   0.000000 &  0.000000 &   0.000000 \\
32 &   7    &  0 &   0.000000 &  0.000000 &   0.000000 \\
33 &  57    & 25 &  30.500000 &  8.500000 &  22.000000 \\
34 &  35    & 18 &  34.000000 &  0.000000 &  34.000000 \\
35 &  92    & 55 &  37.400000 &  6.800000 &  30.600000 \\
36 &  77    & 29 &  27.400000 & 13.200000 &  14.200000 \\
37 &  87    & 41 &  32.000000 &  3.900000 &  28.100000 \\
38 &  67    & 19 &  22.100000 & 15.100000 &   7.000000 \\
39 &  14    &  8 &  36.400000 &  0.000000 &  36.400000 \\
40 &  32    &  0 &   0.000000 &  0.000000 &   0.000000 \\
42 &   2    &  5 &  71.400000 &  0.000000 &  71.400000 \\
45 &  34    &  7 &  17.100000 & 17.100000 &   0.000000 \\
48 &  23    & 16 &  41.000000 & 17.900000 &  23.100000 \\
49 &   8    &  4 &  33.300000 & 33.300000 &   0.000000 \\
50 &  20    &  8 &  28.600000 &  0.000000 &  28.600000 \\
51 &  41    &  2 &   4.700000 &  0.000000 &   4.700000 \\
52 &  14    &  7 &  33.300000 & 33.300000 &   0.000000 \\
53 &  38    & 19 &  33.300000 &  8.800000 &  24.600000 \\
54 &   9    & 25 &  73.500000 &  0.000000 &  73.500000 \\
55 &   0    &  7 & 100.000000 &  0.000000 & 100.000000 \\
56 &  15    & 28 &  65.100000 & 32.600000 &  32.600000 \\
57 &  15    &  0 &   0.000000 &  0.000000 &   0.000000 \\
58 &   7    &  5 &  41.700000 &  0.000000 &  41.700000 \\
59 &  14    & 20 &  58.800000 & 11.800000 &  52.900000 \\
60 &   0    &  8 & 100.000000 &  0.000000 & 100.000000 \\
61 &  21    &  0 &   0.000000 &  0.000000 &   0.000000 \\
62 &   8    &  0 &   0.000000 &  0.000000 &   0.000000 \\
63 &  87    & 20 &  18.700000 &  3.700000 &  15.000000 \\
64 &   9    &  0 &   0.000000 &  0.000000 &   0.000000 \\
70 &   0    & 14 & 100.000000 &  0.000000 & 100.000000 \\
72 &   0    & 17 & 100.000000 & 41.200000 &  58.800000 \\
73 &  43    & 24 &  35.800000 & 26.900000 &   9.000000 \\
75 &   8    &  0 &   0.000000 &  0.000000 &   0.000000 \\
78 &  10    &  6 &  37.500000 &  0.000000 &  37.500000 \\
79 &  12    &  0 &  0.000000  &  0.000000 &   0.000000 \\
80 &  12    &  0 &  0.000000  &  0.000000 &   0.000000 \\
87 &   7    &  0 &  0.000000  &  0.000000 &   0.000000 \\
99 &  19    &  0 &  0.000000  &  0.000000 &   0.000000 \\
    \bottomrule
\end{longtblr}

\end{document}

在此处输入图片描述

相关内容