\documentclass[11pt]{article}
\usepackage{lmodern} % 使用现代Computer Modern字体
\usepackage{setspace} % 设置文档的行距
\usepackage{amsmath, amsfonts, amssymb} % 数学公式排版
\usepackage{bbm} % 处理数学符号
\usepackage{multicol} % 创建多栏布局
\usepackage{multirow} % 跨行的单元格
\usepackage[top=1in, bottom=1in, left=1in, right=1in]{geometry} % 页面布局
\usepackage[normalem]{ulem} % either use this package to strikeout a text 删除或下划线
\usepackage{caption} % 处理表格和图形的标题
% 表格相关
\usepackage{booktabs} % 三线表
\usepackage{makecell} % 表格内换行
\usepackage{float}
\usepackage{array}
\usepackage{tabularx} % 设置表格的宽度
\usepackage{ragged2e} % for \RaggedRight macro
\usepackage{longtable} % 表格跨页
\usepackage{tabularray}
\usepackage{microtype} % 改善对齐
\begin{document}
%---------------------------------------------------------
% 生成Table1的Panel A
\newcommand*{\tapa}{
{Panel A: Sample selection of site visits} & \\
& {No. of Total IR Activities} \\
{1.Total IR activities} & 99,605 \\
{2.The IR activities involving sell-side analysts} & 43,450 \\
{3.The IR activities involving mutual fund managers} & 24,393 \\
{4.The IR activities involving sell-side analysts and mutual fund managers} & 19,323 \\
{Site visit} & 17,870 \\
{Analyst meeting, Road show, and other meetings initiated by sell-side analysts} & 1,116 \\
{Performance announcement meeting, Public news meeting, Media interview, and Others} & 597 \\
}
% Panel B
\newcommand*{\tapb}{
Panel B: The number of site visits involving analysts and managers & & & & & \\
Year & involving analysts & involving managers & Co-visit & (3)/(1) & (3)/(2) \\
& (1) & (2) & (3) & (4) & (5) \\
2007 & 316 & 182 & 64 & 0.203 & 0.352 \\
2008 & 290 & 156 & 82 & 0.283 & 0.526 \\
2009 & 440 & 255 & 132 & 0.300 & 0.518 \\
2010 & 575 & 297 & 155 & 0.270 & 0.522 \\
2011 & 529 & 240 & 140 & 0.265 & 0.583 \\
2012 & 2,148 & 1,246 & 910 & 0.424 & 0.730 \\
2013 & 4,839 & 2,806 & 2,107 & 0.435 & 0.751 \\
2014 & 5,150 & 3,057 & 2,363 & 0.459 & 0.773 \\
2015 & 4,358 & 2,649 & 2,064 & 0.474 & 0.779 \\
2016 & 4,842 & 2,582 & 2,127 & 0.439 & 0.824 \\
2017 & 4,497 & 2,088 & 1,736 & 0.386 & 0.831 \\
2018 & 3,657 & 1,730 & 1,443 & 0.395 & 0.834 \\
2019 & 3,116 & 1,488 & 1,255 & 0.403 & 0.843 \\
2020 & 3,649 & 2,297 & 1,954 & 0.535 & 0.851 \\
2021 & 4,367 & 2,805 & 2,302 & 0.527 & 0.821 \\
Total & 42,773 & 23,878 & 18,834 & NA & NA \\
Avg. & 2,852 & 1,592 & 1,256 & 0.386 & 0.703 \\
}
% Panel C
\newcommand*{\tapc}{
Panel C: The ratio of visiting analysts and managers & & & & & & \\
Year & Avg. Act Analyst & Avg. Visit Analyst & (2)/(1) & Avg. Act Manager & Avg. Visit Manager & (5)/(4) \\
& (1) & (2) & (3) & (4) & (5) & (6) \\
2007 & 19.073 & 2.640 & 0.138 & 7.035 & 1.433 & 0.204 \\
2008 & 21.643 & 3.735 & 0.173 & 7.576 & 1.500 & 0.198 \\
2009 & 22.092 & 4.023 & 0.182 & 8.950 & 1.458 & 0.163 \\
2010 & 24.925 & 3.593 & 0.144 & 10.417 & 1.553 & 0.149 \\
2011 & 18.965 & 3.538 & 0.187 & 11.078 & 1.697 & 0.153 \\
2012 & 22.580 & 11.258 & 0.499 & 11.200 & 4.636 & 0.414 \\
2013 & 26.067 & 17.620 & 0.676 & 12.028 & 6.940 & 0.577 \\
2014 & 24.526 & 19.433 & 0.792 & 12.570 & 7.092 & 0.564 \\
2015 & 23.844 & 18.833 & 0.790 & 13.230 & 7.000 & 0.529 \\
2016 & 24.319 & 20.684 & 0.851 & 12.654 & 6.660 & 0.526 \\
2017 & 28.151 & 22.400 & 0.796 & 13.675 & 6.732 & 0.492 \\
2018 & 33.348 & 22.429 & 0.673 & 13.703 & 7.703 & 0.562 \\
2019 & 30.305 & 21.470 & 0.708 & 14.014 & 7.041 & 0.502 \\
2020 & 31.359 & 23.547 & 0.751 & 14.422 & 9.896 & 0.686 \\
2021 & 30.000 & 24.106 & 0.804 & 15.521 & 10.445 & 0.673 \\
Avg. & 25.413 & 14.621 & 0.544 & 11.872 & 5.452 & 0.426 \\
}
\newcommand*{\tapd}{
Panel D: The number of analysts and managers in each joint site visit & & & & \\
Year & Avg. of broker & Avg. of analyst & Avg. of fund company & Avg. of fund manager \\
& (1) & (2) & (3) & (4) \\
2007 & 1.266 & 1.422 & 1.844 & 1.953 \\
2008 & 1.524 & 1.866 & 2.049 & 2.159 \\
2009 & 1.568 & 1.773 & 1.886 & 1.955 \\
2010 & 1.555 & 1.684 & 1.787 & 1.865 \\
2011 & 1.550 & 1.814 & 1.664 & 1.750 \\
2012 & 2.257 & 2.693 & 2.171 & 2.491 \\
2013 & 2.345 & 2.782 & 2.243 & 2.601 \\
2014 & 2.433 & 2.887 & 2.487 & 2.809 \\
2015 & 2.391 & 2.897 & 2.598 & 2.976 \\
2016 & 2.748 & 3.360 & 2.366 & 2.702 \\
2017 & 3.314 & 4.055 & 2.344 & 2.695 \\
2018 & 3.835 & 4.648 & 3.094 & 3.824 \\
2019 & 3.430 & 4.221 & 3.008 & 3.865 \\
2020 & 2.907 & 3.931 & 4.970 & 6.973 \\
2021 & 3.330 & 4.314 & 5.540 & 7.143 \\
Avg. & 2.430 & 2.957 & 2.670 & 3.184 \\
}
%------------------------------------------
% 表格开始
\begin{center}
\SetTblrOuter[tblr]{
expand = \tapa
}
\begin{table}[H]
\centering
\caption{Site Visits of Sell-Side Analysts and Mutual Fund Managers}
\SetTblrInner[tblr]{
width = 1.0\linewidth,
cells = {c,m,font=\tiny}, %
colspec = {X[l,7cm]X[l,2cm]},
stretch = 0.6, %
rowsep = 0.6pt, %
cell{1}{1} = {c=2, r=1}{l}, %
hline{2,3,Z} = {0.05em}, %
hline{7} = {0.03em},
row{1} = {ht=0.5cm,font=\small},
hspan = minimal, %
}
\begin{tblr}{}
\tapa
\end{tblr}
% \vspace*{-0.6cm}
%---------------------------------------------------------
\SetTblrOuter[tblr]{
expand = \tapb
}
\SetTblrInner[tblr]{
width = 1.0\linewidth,
cells = {c,m,font=\tiny}, %
colspec = {X[c,0.5cm]X[c,1.7cm]X[c,1.9cm]X[c,1.3cm]X[c,1.3cm]X[c,1.3cm]},
% 行距
stretch = 0.6, %
rowsep = 0.6pt, %
cell{1}{1} = {c=6, r=1}{l}, %
hline{2,3,Z} = {0.05em}, %
hline{4,Y,X} = {0.03em}, %
row{1} = {ht=0.5cm,font=\small},
hspan = minimal, %
}
\begin{tblr}{}
\tapb
\end{tblr}
%---------------------------------------------------------
\SetTblrOuter[tblr]{
expand = \tapc
}
\SetTblrInner[tblr]{
width = 1.0\linewidth,
cells = {c,m,font=\tiny}, %
colspec = {X[c,0.5cm]X[c,1.3cm]X[c,1.3cm]X[c,1cm]X[c,1.3cm]X[c,1.3cm]X[c,1cm]},
stretch = 0.6, %
rowsep = 0.6pt, %
cell{1}{1} = {c=7, r=1}{l}, %
hline{2,3,Z} = {0.05em}, %
hline{4,Y} = {0.03em}, %
row{1} = {ht=0.5cm,font=\small},
hspan = minimal, %
}
\begin{tblr}{}
\tapc
\end{tblr}
\SetTblrOuter[tblr]{
expand = \tapd
}
\SetTblrInner[tblr]{
width = 1.0\linewidth,
cells = {c,m,font=\tiny}, %
colspec = {X[c,0.5cm]X[c,1.8cm]X[c,1.8cm]X[c,2.3cm]X[c,2.3cm]},
stretch = 0.6, %
rowsep = 0.6pt, %
cell{1}{1} = {c=5, r=1}{l}, %
hline{2,3,Z} = {0.05em}, %
hline{4,Y} = {0.03em}, %
row{1} = {ht=0.5cm,font=\small},
hspan = minimal, %
}
\begin{tblr}{}
\tapd
\end{tblr}
\end{table}
\end{center}
\end{document}
%---------------------------------------------------------
该长表格由五个不同列数的panel构成。如何用latex输出该表格,且在下一页的开头重复所属panel的表头?尽量用tabularray或longtblr。
多谢回复,已经在问题中添加了代码。
@u134749 你好,
longtblr
应该是所有列的列数都相同的效果,你的\tapa
,\tapb
等子表的列数不完全相同,你需要给定如果需要一个跨页的长表格,第一个panel的几列如何垂直对应到第二个panel,如下图:一个标准版的
longtblr
应该如下所示(具有明显的方便对齐的align锚点):另外,建议你思考:真的需要要把5个列数(或者说列格式)如此不统一的表格纵向堆叠成一个长表格吗?
@u70550 再次感谢您的回复。目前是有这个需求,是否能用别的方法实现?比如独立生成多个panel,再外面嵌套一层将其合并?
@u134749 我觉得要实现你说的,它可以是5个
longtblr
,这样可以做到每个表如果跨页就会重复表头。嗯嗯。我试试,谢谢啦~
@u134749 你想重复显示的表头指的是 Panel那一行还是指标的那一行呢? 另外你是否在交流群(91940767)内?
如果想重复Panel那一行,可以用
rowhead=1
;如果想重复Panel和指标共两行,可以用
rowhead=2
;如果只想重复指标的那一行,可能需要让
Panel
不在第一行我本来想修改原回复的,但是已经采纳乐,我对
tabularray
宏包并不那么熟悉...所以我并没有解决你的问题,下面是我的一个不那么好的解答吧...不那么好的原因是:一是没有把5个panel的
longtblr
合并为一个浮动体table
(这个也说明了我这个思路不够好);二是觉得代码还有很多可以复用以及利用样式更快捷实现的地方;
几处需要注意的地方:
tabularray
宏包提供了\UseTblrLibrary{booktabs}
方便直接插入三线表而不用手动指定;presep=5pt,postsep=0pt,
让5个longtblr
更紧凑default
的方法,并暂时把Panelxxx
作为caption
(其实我觉得这不太好,但暂时没想到其他好办法...)下面的MWE并不elegant...
效果如下图:
也希望有大神帮我改改上面的代码?
and:对于多个列格式完全不相同的有跨页需求的表格,如何排版才能让他们即跨页方便,又可以直接纵向堆叠并使用
table
实现浮动呢?@u70550 这里的"浮动"措辞有误,感谢@u19850 指出。