书本标签和交叉引用无法与横向表格配合使用

书本标签和交叉引用无法与横向表格配合使用

通过修改@zarko 最近的一项建议,我在表格中遇到了一些新问题。首先,我找不到使用 /hiline 或 /toprule 添加水平线的方法。第二个问题是 \cref 无法引用我的表格。

我的代码:

 \documentclass[12pt]{article}
  \usepackage[a4paper,
    hmargin=15mm, vmargin={1cm,2cm}]{geometry}
 \usepackage[USenglish]{babel}
 \usepackage{microtype}
 \usepackage{cleveref}
\usepackage{pdflscape}
\usepackage{rotating}
\usepackage{makecell}
\usepackage{xcolor}
\usepackage{tabularray}
\UseTblrLibrary{booktabs, siunitx}
  \ExplSyntaxOn
\NewChildSelector{eachtwo}
 {
  \int_step_inline:nnnn {6}{2}{\l_tblr_childs_total_tl}
  { \clist_put_right:Nn \l_tblr_childs_clist {##1} }
}
     \ExplSyntaxOff
\begin{document}


\cref{tab2} reports probit results


\begin{landscape}\label{tab:tab2}
\small
  \sisetup{
input-open-uncertainty =,
input-close-uncertainty=,
table-align-text-after=false,
table-align-text-before=false,
table-format={(}-1.3{**}
    }

\begin{longtblr}[
 caption = {Push and pull factors associated with Surges: Probit model},
note{} = {Standard errors in parentheses:\newline
      *:    $p<0.10$,\quad
      **:   $p<0.05$,\quad
      ***:  $p<0.01$.},
            ]{
rowhead= 2,
colsep = 2pt,
colspec= {@{} X[l,h, font=\scshape\linespread{0.84}\selectfont]
              *{12}{S}
          @{}},
row{1} = {font=\small\bfseries},
row{4-Z} = {rowsep = 0pt},
row{eachtwo} = {abovesep=1ex},
  \toprule              }
  &{{{(1)}}}  &{{{(2)}}}  &{{{(3)}}}  &{{{(4)}}}  &{{{(5)}}}  &{{{(6)}}}
&{{{(7)}}}  &{{{(8)}}}  &{{{(9)}}}   \\
\midrule
 %%%%
\SetCell[c=13]{c, font=\itshape, bg=gray8}    Pull Factors
&   &   &   &   &   &   &   &   &   &   &   &            \\
 %%%%
    \midrule

Size of the economy &   -0.014         &   -0.016         &   -0.018         &   -0.018         &   -0.015         &   -0.015         &   -0.019         &   -0.024         &    0.101         \\
            &  (-1.11)         &  (-1.20)         &  (-1.19)         &  (-1.18)         &  (-0.80)         &  (-0.76)         &  (-1.00)         &  (-0.80)         &   (1.10)         \\
\SetCell[r=2]{l} 
Level of economic development &                  &    0.010         &    0.005         &    0.005         &    0.004         &    0.004         &    0.012         &    0.021         &   -0.232         \\
            &                  &   (0.49)         &   (0.21)         &   (0.21)         &   (0.14)         &   (0.13)         &   (0.36)         &   (0.49)         &  (-1.61)         \\
\SetCell[r=2]{l} 
Trade (\% of GDP) &                  &                  &    0.028         &    0.028         &    0.043         &    0.032         &    0.024         &    0.045         &    0.709\TblrNote{**} \\
            &                  &                  &   (0.59)         &   (0.59)         &   (0.69)         &   (0.48)         &   (0.39)         &   (0.56)         &   (1.96)         \\
  \SetCell[r=2]{l} 
   Bilateral Investment Treaty (BIT) with U.S&                  &                  &                  &    0.000         &   -0.008         &   -0.039         &   -0.053         &   -0.043         &   -0.523\TblrNote{*}  \\
            &                  &                  &                  &   (0.01)         &  (-0.10)         &  (-0.45)         &  (-0.65)         &  (-0.41)         &  (-1.74)         \\
 \SetCell[r=2]{l} 
Real interest rate&                  &                  &                  &                  &    0.001         &    0.000         &    0.001         &    0.005         &    0.017\TblrNote{*}  \\
            &                  &                  &                  &                  &   (1.00)         &   (0.10)         &   (0.84)         &   (1.08)         &   (1.66)         \\
   \SetCell[r=2]{l} 
Inflation ((log annual \%)&                  &                  &                  &                  &                  &    0.002         &   -0.000         &   -0.028         &   -0.031         \\
            &                  &                  &                  &                  &                  &   (0.07)         &  (-0.00)         &  (-0.56)         &  (-0.27)         \\
   \SetCell[r=2]{l} 
   Exchange rate peg&                  &                  &                  &                  &                  &                  &   -0.032         &   -0.091         &   -0.165         \\
            &                  &                  &                  &                  &                  &                  &  (-0.42)         &  (-0.87)         &  (-0.57)         \\
   \SetCell[r=2]{l} 
 Capital inflow restrictions&                  &                  &                  &                  &                  &                  &                  &    0.120         &   -0.336         \\
            &                  &                  &                  &                  &                  &                  &                  &   (0.69)         &  (-0.61)         \\
           \SetCell[r=2]{l} 
            Capital flow volatility (CFV)&                  &                  &                  &                  &                  &                  &                  &                  &   -0.029         \\               &                  &                  &                  &                  &                  &                  &                  &                        &  (-0.96)         \\
%%%%% 
                  \midrule
                 \SetCell[r=2,c=13]{c, font=\itshape, bg=gray8}    Push Factors 
    &   &   &   &   &   &   &   &   &   &   &   \\
&   &   &   &   &   &   &   &   &   &   &   \\
      %%%%%
              \SetCell[r=2]{l} 
               Global risk aversion (VIX) index&                  &                  &                  &                  &                  &    0.001         &                  &                  &                  \\
            &                  &                  &                  &                  &                  &   (0.14)         &                  &                  &                  \\

      \SetCell[r=2]{l} 
       BIS global liquidity indicator&                  &                  &                  &                  &                  &                  &    0.000         &                  &                  \\
            &                  &                  &                  &                  &                  &                  &   (0.40)         &                  &                  \\

 \SetCell[r=2]{l} 
  volatility of portfolio outflows&                  &                  &                  &                  &                  &                  &                  &    0.000\TblrNote{***}&                  \\
            &                  &                  &                  &                  &                  &                  &                  &   (2.59)         &                  \\

    \SetCell[r=2]{l} 
    US shadow rate  &                  &                  &                  &                  &                  &                  &                  &                  &    0.015         \\
            &                  &                  &                  &                  &                  &                  &                  &                  &   (0.40)         \\
        \SetCell[r=2]{l} 
        Constant        &   -0.688\TblrNote{**} &   -0.723\TblrNote{**} &   -0.749\TblrNote{*}  &   -0.748\TblrNote{*}  &   -0.914\TblrNote{*}  &   -0.860         &   -0.758         &   -0.822         &   -4.363         \\
            &  (-2.29)         &  (-2.36)         &  (-1.84)         &  (-1.82)         &  (-1.79)         &  (-1.49)         &  (-1.42)         &  (-1.03)         &  (-1.60)         \\
      \hline
      Observations    &     3193         &     3192         &     3022         &     3022         &     2139         &     1739         &     1978         &     1236         &      222         \\
    Pseudo \(R^{2}\)&    0.000         &    0.001         &    0.001         &    0.001         &    0.002         &    0.001         &    0.002         &    0.007         &    0.051         \\
   \bottomrule
   \end{longtblr}
   \end{landscape}
   \end{document}

在此处输入图片描述

答案1

  • 标签名称和引用名称必须相等且唯一,例如在您的情况下tab:tab2
  • 环境无法被标记和引用,
  • 标签总是考虑它之前的计数器,例如在图形或表格中,必须在标题之后
  • 标签语法longtblr与其他(经典)表中的语法不同,正如@leandriis 在他的回答中提到的那样
  • 您的 MWE 除了引用表格的问题之外,还存在其他问题:
    • 表有 10 列,但您定义了 13 列
    • \toprule不应成为表格序言(表格设计规范)的一部分,
    • 如果表格有 10 列(就像您的表格一样),那么每行必须有 9 个与号(无论行中的某些单元格是否合并为多列单元格)

更正后的 MWE(仅包含前几行)为:

\documentclass[12pt]{article}
\usepackage[a4paper,
            hmargin=15mm, vmargin={1cm,2cm}]{geometry}
\usepackage[USenglish]{babel}
\usepackage{microtype}
\usepackage{pdflscape}
\usepackage{rotating}
\usepackage{makecell}
\usepackage{xcolor}
\usepackage{tabularray}
\UseTblrLibrary{booktabs, siunitx}
\ExplSyntaxOn
\NewChildSelector{eachtwo}
{
\int_step_inline:nnnn {5}{2}{\l_tblr_childs_total_tl}
{ \clist_put_right:Nn \l_tblr_childs_clist {##1} }
}
\ExplSyntaxOff
 
\usepackage{cleveref}

\begin{document}
\cref{tab:tab2} reports probit results

\begin{landscape}%\label{tab:tab2} you can not label landscape environment!
\small
\sisetup{
input-open-uncertainty =,
input-close-uncertainty=,
table-align-text-after=false,
table-align-text-before=false,
table-format={(}-1.3{**}
}

\begin{longtblr}[
caption = {Push and pull factors associated with Surges: Probit model},
  label = {tab:tab2},
 note{} = {Standard errors in parentheses:\newline
            *:    $p<0.10$,\quad
            **:   $p<0.05$,\quad
            ***:  $p<0.01$.},
                ]{
    rowhead = 2,
     colsep = 2pt,
    colspec = {@{} X[l,h, font=\scshape\linespread{0.84}\selectfont]
               *{9}{S}
               @{}},
    row{1} = {font=\small\bfseries},
    row{4-Z} = {rowsep = 0pt},
    row{eachtwo} = {abovesep=1ex},
                    }
    \toprule              
    &{{{(1)}}}  &{{{(2)}}}  &{{{(3)}}}  &{{{(4)}}}  &{{{(5)}}}  
    &{{{(6)}}}  &{{{(7)}}}  &{{{(8)}}}  &{{{(9)}}}   \\
    \midrule
%%%%
\SetCell[c=10]{c, font=\itshape, bg=gray8}    Pull Factors
    &           &           &           &           &   
    &           &           &           &           \\
%%%%
    \midrule
Size of the economy 
    & -0.014    & -0.016    & -0.018    & -0.018    & -0.015    
    & -0.015    & -0.019    & -0.024    &  0.101    \\
    &(-1.11)    &(-1.20)    &(-1.19)    &(-1.18)    &(-0.80)
    &(-0.76)    &(-1.00)    &(-0.80)    &(1.10)     \\
\SetCell[r=2]{l}    Level of economic development 
    &           &  0.010    &  0.005    &  0.005    & 0.004         
    &  0.004    &  0.012    &  0.021    & -0.232    \\
    &           & (0.49)    & (0.21)    & (0.21)    & (0.14)         
    & (0.13)    & (0.36)    & (0.49)    & (-1.61)   \\
\SetCell[r=2]{l}    Trade (\% of GDP) 
    &           &           &  0.028    &  0.028    &  0.043         
    &  0.032    &  0.024    &  0.045    &  0.709\TblrNote{**} \\
    &           &           & (0.59)    & (0.59)    & (0.69)         
    & (0.48)    & (0.39)    & (0.56)    & (1.96)    \\
% other table rows
    \bottomrule
\end{longtblr}
\end{landscape}
\end{document}

在此处输入图片描述

顺便说一句,我建议您将表格的其余部分按照上面的例子进行排列。

答案2

放在\label \caption

答案3

longtable包中的语法与通常的tabularray语法略有不同,用于将 添加label到表中。而不是将\label{<key>}其用作环境label=<key>的可选参数longtable

相关内容