表格標題位置

表格標題位置

我想將標題一直放在表格的左側,但保持整個表格居中,但不知道該怎麼做。有專家可以幫我解決這個問題嗎?非常感謝!

\documentclass{article}
\usepackage{booktabs,caption}
\usepackage[flushleft]{threeparttable}

\begin{document}
\begin{table}[htbp]

\footnotesize
\caption{Summary Statistic}
\label{Summary_statistic}
\topmargin=-25pt
\begin{center}
\scriptsize
\textbf{Table \ref{summary}: Descriptive Statistic}\\
\begin{tabular}{lccccc}
\toprule
                    &           N&        Mean&          SD&         Min&         Max\\
\midrule
\multicolumn{1}{l}{\textbf{\textit{Panel A: Internet Use Frequency:}}}&            &            &            &            &            \\
Heavy Usage         &      77,895&       0.249&       0.433&           0&           1\\
\\ \multicolumn{1}{l}{\textbf{\textit{Panel B: Individual Characteristics:}}}&            &            &            &            &            \\
Foreigner           &      77,895&       0.032&       0.176&           0&           1\\
Female              &      77,895&       0.550&       0.498&           0&           1\\
Parental Status     &      77,895&       0.402&       0.490&           0&           1\\
Household Size      &      77,895&       2.598&       1.359&           1&          10\\
Employed            &      77,895&       0.479&       0.500&           0&           1\\
Unemployed          &      77,895&       0.146&       0.353&           0&           1\\
Not in labor force  &      77,895&       0.375&       0.484&           0&           1\\
Divorced/Seperated  &      77,895&       0.084&       0.277&           0&           1\\
Married             &      77,895&       0.638&       0.480&           0&           1\\
Single              &      77,895&       0.176&       0.381&           0&           1\\
Widow               &      77,895&       0.101&       0.302&           0&           1\\
Age                 &      77,895&      49.817&      18.113&          15&          99\\
\\ \multicolumn{1}{l}{\textbf{\textit{Panel C: LTE Availability:}}}&            &            &            &            &            \\
Urban LTE Availability&      77,895&       0.604&       0.334&           0&           1\\
Rural LTE Availability&      77,895&       0.222&       0.309&           0&           1\\
Urban               &      77,895&       0.664&       0.472&           0&           1\\
Overall LTE availability &      77,895&       0.478&       0.378&           0&           1\\
\bottomrule
\end{tabular}
\end{center}
\end{table}
\end{document}

在此輸入影像描述

答案1

\multicolumn使用刪除面板標題的表格列分隔@{},即

\multicolumn{1}{@{}l}{...}

在此輸入影像描述

\documentclass{article}

\usepackage{booktabs,siunitx}
\newcommand{\panelfont}{\bfseries\itshape}

\begin{document}

\begin{table}
  \centering
  \textbf{Table 6: Descriptive Statistic}

  \begin{tabular}{
      l %
      S[table-format=5,group-separator={,}] % N
      S[table-format=2.3] % Mean
      S[table-format=2.3] % SD
      S[table-format=2] % Min
      S[table-format=2] %Max
  }
    \toprule
                             &  {N}  & {Mean} &  {SD}  & {Min} & {Max} \\
    \midrule
    \multicolumn{1}{@{}l}{\panelfont Panel A: Internet Use Frequency:}    \\
    Heavy Usage              & 77895 &  0.249 &  0.433 &   0   &   1   \\
    \addlinespace
    \multicolumn{1}{@{}l}{\panelfont Panel B: Individual Characteristics:}\\
    Foreigner                & 77895 &  0.032 &  0.176 &   0   &   1   \\
    Female                   & 77895 &  0.550 &  0.498 &   0   &   1   \\
    Parental Status          & 77895 &  0.402 &  0.490 &   0   &   1   \\
    Household Size           & 77895 &  2.598 &  1.359 &   1   &  10   \\
    Employed                 & 77895 &  0.479 &  0.500 &   0   &   1   \\
    Unemployed               & 77895 &  0.146 &  0.353 &   0   &   1   \\
    Not in labor force       & 77895 &  0.375 &  0.484 &   0   &   1   \\
    Divorced/Seperated       & 77895 &  0.084 &  0.277 &   0   &   1   \\
    Married                  & 77895 &  0.638 &  0.480 &   0   &   1   \\
    Single                   & 77895 &  0.176 &  0.381 &   0   &   1   \\
    Widow                    & 77895 &  0.101 &  0.302 &   0   &   1   \\
    Age                      & 77895 & 49.817 & 18.113 &  15   &  99   \\
    \addlinespace
    \multicolumn{1}{@{}l}{\panelfont Panel C: LTE Availability:}          \\
    Urban LTE Availability   & 77895 &  0.604 &  0.334 &   0   &   1   \\
    Rural LTE Availability   & 77895 &  0.222 &  0.309 &   0   &   1   \\
    Urban                    & 77895 &  0.664 &  0.472 &   0   &   1   \\
    Overall LTE availability & 77895 &  0.478 &  0.378 &   0   &   1   \\
    \bottomrule
  \end{tabular}
\end{table}

\end{document}

答案2

我對你的設計感到困惑,想知道為什麼你不把描述放在標題中。我曾經tabularray完成了表格的佈局,並做了一些美化。不知道是否符合你的期望。

\documentclass{article}
\usepackage{xcolor}
\usepackage{tabularray}
\begin{document}
\begin{table}
\caption{Summary Statistic}
\label{Summary_statistic}
This table reports summary statistics of the analytical sample during the period from 2012 to 2014. Panel A shows heavy Internet user status based on people's Internet usage. Panel B shows individual characteristics. Panel C shows the summary statistics of residential LTE broadband availability.\\
\begin{center}
\textbf{\tablename~\ref{Summary_statistic}\\Continued\\Internet use and cybercrimes: OLS analysis}\\
\begin{tblr}
{
colspec         = {Q[c,m]Q[c,m]Q[c,m]Q[c,m]Q[c,m]Q[c,m]},
hline{1,Z}      = {wd=.08em},
hline{2}        = {wd=.05em},
cell{2,4,17}{1} = {c=6}{font=\bfseries\itshape,halign=l,bg=gray9!50},
}
                                     & N      & Mean   & SD     & Min & Max \\
Panel A: Internet Use Frequency:     &        &        &        &     &     \\
Heavy Usage                          & 77,895 & 0.249  & 0.433  & 0   & 1   \\
Panel B: Individual Characteristics: &        &        &        &     &     \\
Foreigner                            & 77,895 & 0.032  & 0.176  & 0   & 1   \\
Female                               & 77,895 & 0.550  & 0.498  & 0   & 1   \\
Parental Status                      & 77,895 & 0.402  & 0.490  & 0   & 1   \\
Household Size                       & 77,895 & 2.598  & 1.359  & 1   & 10  \\
Employed                             & 77,895 & 0.479  & 0.500  & 0   & 1   \\
Unemployed                           & 77,895 & 0.146  & 0.353  & 0   & 1   \\
Not in labor force                   & 77,895 & 0.375  & 0.484  & 0   & 1   \\
Divorced/Seperated                   & 77,895 & 0.084  & 0.277  & 0   & 1   \\
Married                              & 77,895 & 0.638  & 0.480  & 0   & 1   \\
Single                               & 77,895 & 0.176  & 0.381  & 0   & 1   \\
Widow                                & 77,895 & 0.101  & 0.302  & 0   & 1   \\
Age                                  & 77,895 & 49.817 & 18.113 & 15  & 99  \\
Panel C: LTE Availability:           &        &        &        &     &     \\
Urban LTE Availability               & 77,895 & 0.604  & 0.334  & 0   & 1   \\
Rural LTE Availability               & 77,895 & 0.222  & 0.309  & 0   & 1   \\
Urban                                & 77,895 & 0.664  & 0.472  & 0   & 1   \\
Overall LTE availability             & 77,895 & 0.478  & 0.378  & 0   & 1   \\
\end{tblr}
\end{center}
\end{table}
\end{document}

在此輸入影像描述

答案3

我不確定我是否理解您的格式化目標,

我想將標題一直放在表格的左側,但保持整個表格居中

我將此目標解釋為需要結合使用 (a) 一個threeparttable環境來封裝\caption指令和tabular環境,以及 (b)\captionsetup帶有選項justification=raggedright和 的指令singlelinecheck=false

我不禁發現\multicolumn{1}{l}{...}三個字幕的包裝是多餘的。要么完全省略這些包裝器,要么用包裝器替換它們\multicolumn{6}{l}{...}——就像我在下面的程式碼中所做的那樣。

以下螢幕截圖邊緣的框架線是因為showframe為此測試文件載入了套件而繪製的。您無需在實際文件中載入此套件。

在此輸入影像描述

\documentclass{article}
\usepackage{booktabs,caption}
\usepackage[flushleft]{threeparttable}

\usepackage{showframe} % just for this example

\begin{document}
\null % just for this example

\begin{table}[htbp]
\captionsetup{font={bf,footnotesize}, % not sure about "bf"
              justification=raggedright,
              singlelinecheck=false,
              skip=0.25\baselineskip}
\centering
\footnotesize

\begin{threeparttable}
\caption{Summary Statistics}
\label{Summary_statistic}

%\scriptsize % why so many font size changes, and why \scriptsize?
%\textbf{Table \thetable: Descriptive Statistics}\\ % redundant, no?

\begin{tabular}{@{} l ccccc @{}}
\toprule
                    &           N&        Mean&          SD&         Min& Max\\
\midrule
\multicolumn{6}{@{}l}{\textbf{\textit{Panel A: Internet Use Frequency}}} \\
Heavy Usage         &      77,895&       0.249&       0.433&           0& 1 \\
\addlinespace
\multicolumn{6}{@{}l}{\textbf{\textit{Panel B: Individual Characteristics}}} \\
Foreigner           &      77,895&       0.032&       0.176&           0& 1 \\
Female              &      77,895&       0.550&       0.498&           0& 1 \\
Parental Status     &      77,895&       0.402&       0.490&           0& 1 \\
Household Size      &      77,895&       2.598&       1.359&           1& 10\\
Employed            &      77,895&       0.479&       0.500&           0& 1 \\
Unemployed          &      77,895&       0.146&       0.353&           0& 1 \\
Not in labor force  &      77,895&       0.375&       0.484&           0& 1 \\
Divorced/Seperated  &      77,895&       0.084&       0.277&           0& 1 \\
Married             &      77,895&       0.638&       0.480&           0& 1 \\
Single              &      77,895&       0.176&       0.381&           0& 1 \\
Widow               &      77,895&       0.101&       0.302&           0& 1 \\
Age                 &      77,895&      49.817&      18.113&          15& 99\\
\addlinespace
\multicolumn{6}{@{}l}{\textbf{\textit{Panel C: LTE Availability}}} \\
Urban LTE Availability&    77,895&       0.604&       0.334&           0& 1 \\
Rural LTE Availability&    77,895&       0.222&       0.309&           0& 1 \\
Urban                 &    77,895&       0.664&       0.472&           0& 1 \\
Overall LTE availability & 77,895&       0.478&       0.378&           0& 1 \\
\bottomrule
\end{tabular}
\end{threeparttable}
\end{table}

\end{document}

答案4

  • 使用tabularray打包,其中標題格式留給caption打包。
  • 使用的是talltblrtable,tabularray相當於threeparttable.

編輯:

  • 對於面板標題定義了新命令(通過\NewTableComman),它收集該行的設定:\setCell[c=6]{...}、字體形狀和外觀
  • 由於 \SetCell 無法(據我所知)使用@{}面板標題文字的縮排(掛起)來更改單元格列分隔,因此\panel引入命令 `\SetRow{...} 用於在標題上方添加空格(如果需要)並將行內容向左移動:
\documentclass{article}
%---------------- Show page layout. Don't use in a real document!
\usepackage{showframe}
\renewcommand\ShowFrameLinethickness{0.15pt}
\renewcommand*\ShowFrameColor{\color{red}}
%---------------------------------------------------------------%
\usepackage{lipsum}% For dummy text. Don't use in a real document

\usepackage[skip=1ex,
            font={bf,small},
            singlelinecheck=false]{caption}

\usepackage{tabularray}
\UseTblrLibrary{booktabs, siunitx}
    \DefTblrTemplate{caption}{default}{\addtocounter{table}{-1}%
                                       \captionsetup{aboveskip=-1ex, belowskip=1ex}%
                                       \captionof{table}{\InsertTblrText{caption}}}
    \SetTblrStyle{remark}{font=\footnotesize}
\NewTableCommand\panel[1][2ex]{%
        \SetRow{abovesep+=#1, preto=\hspace{-1em}}
        \SetCell[c=6]{font=\bfseries\itshape}
                              }
\sisetup{group-separator={,}}

\begin{document}
\lipsum[66]

\begin{talltblr}[
caption = {Summary Statistic},
  label = {Summary_statistic},
remark{Note} = {N: Number of sample, SD: Standard Deviation}
                ]{colspec = {Q[l,leftsep=1em]
                            Q[c, si={table-format=5.0}]
                            *{2}{Q[c, si={table-format=2.3}]}
                            *{2}{Q[c, si={table-format=2.0}]}
                            },
                 rowsep  = 1pt,
                 row{1}  = {guard},
                 }
    \toprule
                                & N     & Mean      & SD        & Min   & Max   \\
    \midrule
\panel[0pt]
Panel A: Internet Use Frequency:
                                &       &           &           &       &       \\
    Heavy Usage                 & 77895 &  0.249    &  0.433    &  0    &   1   \\
\panel  Panel B: Individual Characteristics:
                                &       &           &           &       &       \\
    Foreigner                   & 77895 &  0.032    &  0.176    &   0   &   1   \\
    Female                      & 77895 &  0.550    &  0.498    &   0   &   1   \\
    Parental Status             & 77895 &  0.402    &  0.490    &   0   &   1   \\
    Household Size              & 77895 &  2.598    &  1.359    &   1   &  10   \\
    Employed                    & 77895 &  0.479    &  0.500    &   0   &   1   \\
    Unemployed                  & 77895 &  0.146    &  0.353    &   0   &   1   \\
    Not in labor force          & 77895 &  0.375    &  0.484    &   0   &   1   \\
    Divorced/Separated          & 77895 &  0.084    &  0.277    &   0   &   1   \\
    Married                     & 77895 &  0.638    &  0.480    &   0   &   1   \\
    Single                      & 77895 &  0.176    &  0.381    &   0   &   1   \\
    Widow                       & 77895 &  0.101    &  0.302    &   0   &   1   \\
    Age                         & 77895 & 49.817    & 18.113    &  15   &  99   \\
\panel  Panel C: LTE Availability:
                                &       &           &           &       &       \\
    Urban LTE Availability      & 77895 &  0.604    &  0.334    &   0   &   1   \\
    Rural LTE Availability      & 77895 &  0.222    &  0.309    &   0   &   1   \\
    Urban                       & 77895 &  0.664    &  0.472    &   0   &   1   \\
    Overall LTE availability    & 77895 &  0.478    &  0.378    &   0   &   1   \\
    \bottomrule
  \end{talltblr}\medskip

\lipsum[11]
\end{document}

在此輸入影像描述

相關內容