2

I have now tried to figure this out for the whole day, but I can't get it working.

My table headers for the longtable with multirow column names are overlapping the data itself. Can someone please help me to understand what I'm doing wrong?

(Most of the code is exported from my Python notebook, but I just can't figure out how to wrap the headers correctly in either Python or 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}
2

2 Answers 2

1

Some suggestions:

  • I suggest you use the xltabular package and its eponymous environment instead of a longtable environment. That way, you can set up automatic linebreaking in the header cells. Basically, an xltabular environment combines the capabilities of the longtable and tabularx environments.

  • I would round the number in the final 3 data columns to just 1 significant decimal digits. This is easily accompilished with the siunitx package and its S column type.

  • Use the macros of the booktabs package to draw well-spaced horizontal lines.

The following screenshot shows the start of the first page of the resulting two-page table.

enter image description here

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

With longtblr defined in the tabularray package`

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

enter image description here

5
  • +1. Just curious why you're setting a precision of 2 decimal digits?
    – Mico
    Jun 13, 2022 at 7:15
  • For some reason, I get an extra "Z" above the table label, which I can't figure out. Also, Overleaf throws a "Missing number, treated as zero" error. Jun 13, 2022 at 7:58
  • @AlexGünsberg, unfortunately Overleaf still has installed quite old version of tabularray package which not support options Z in columns/rows numbering. Hopefully they will upgrade their LaTeX installation soon. Ask their support if and how you can load recent package (2022B) locally to your Overleaf folder.
    – Zarko
    Jun 13, 2022 at 9:42
  • @Zarko many thanks for the advice and the beautiful piece of code! Jun 13, 2022 at 9:57
  • 1
    @AlexGünsberg, your are welcome! Now you have sufficient reputation that you can upvote bot answers :-)
    – Zarko
    Jun 13, 2022 at 10:20

You must log in to answer this question.

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