LaTeX 表格是否独立?

LaTeX 表格是否独立?

我有一个相对复杂的表格,其中对列宽和间距进行了大量手动调整,我试图将其转换为 pdf standalone(目的是最终将其插入 Word 文档)。原始表格文本如下:

\begin{table}[h!]
\begin{center}
\begin{tabularx}{0.7\textwidth}{>{\raggedright\arraybackslash}X  >{\raggedleft\arraybackslash}X }
\hline
\hline
\vspace{1mm}
 & Initiate conflict \\
\Xhline{2\arrayrulewidth}
First = female                      & $-0.08$      \\
                                            & $(0.05)$     \\
Second = prefer not to say         & $-0.21$      \\
                                            & $(0.18)$     \\
Third = non-binary/non-conforming  & $-0.18$      \\
                                            & $(0.12)$     \\
(Intercept)                                 & $0.35^{***}$ \\
                                            & $(0.03)$     \\
\hline
R$^2$                                       & $0.01$       \\
Adj. R$^2$                                  & $0.01$       \\
Num. obs.                                   & $404$        \\
\hline
\hline
\multicolumn{2}{l}{\scriptsize{$^{***}p<0.001$; $^{**}p<0.01$; $^{*}p<0.05$}}
\end{tabularx} \\
\parbox{11cm}{\caption{Random caption inserted as a placeholder for what I am actually going to say, which will be a sentence or two long in the end I think.}}
\label{table:coefficients}
\end{center}
\end{table}

任何有关如何在文档类型中成功实现此工作的指导standalone都将不胜感激。或者,如果有更简单的方法将此类表格放入 Word 文档中,我愿意接受建议。

答案1

我认为使用tabularx两个等宽列的环境以及第一列中的一些后续换行符不会产生良好的布局。我会使用基本tabular环境,l用于第一列,并对齐第二列中的数字。为了强制图例的宽度与其上方的材料相同tabular,我建议您使用threeparttable包装器。

在此处输入图片描述

\documentclass[border=2pt]{standalone}
\usepackage{booktabs,threeparttable,dcolumn}
\newcolumntype{d}[1]{D..{#1}}
\newcommand\mc[1]{\multicolumn{1}{c@{}}{#1}} % handy shortcut macro

\begin{document}

\begin{threeparttable}
\begin{tabular}{@{} l d{2.3} @{}}
\toprule
 & \mc{Initiate conflict} \\
\midrule
First = female                     & -0.08      \\
                                   & (0.05)     \\
Second = prefer not to say         & -0.21      \\
                                   & (0.18)     \\
Third = non-binary/non-conforming  & -0.18      \\
                                   & (0.12)     \\
(Intercept)                        & 0.35^{***} \\
                                   & (0.03)     \\
\addlinespace
R$^2$                              & 0.01       \\
Adj.\ R$^2$                        & 0.01       \\
Num.\ obs.                         & \mc{404}   \\
\midrule[\heavyrulewidth]
\multicolumn{2}{@{}l}{\scriptsize $^{***}\ p<0.001$; $^{**}\ p<0.01$; $^{*}\ p<0.05$} 
\end{tabular}

Random caption inserted as a placeholder for what I am actually going to say, which will be a sentence or two long in the end I think.
\end{threeparttable}

\end{document}

答案2

作为对 @Mico 回答(+1)的赞美,使用该tabularray包,即其talltblr环境相当于经典threeparttable

\documentclass[border=3.141592]{standalone}
\usepackage{xcolor}
\usepackage{tabularray}
\UseTblrLibrary{booktabs,siunitx}
    \SetTblrStyle{remark}{font=\scriptsize}


\begin{document}

\begin{talltblr}[
caption = {Caption text},
  label = {tab:statistic},
remark{Note} = {$^{***}\ p<0.001$; $^{**}\ p<0.01$; $^{*}\ p<0.05$}
                ]{width=0.7\linewidth,      % see @John Kormylo comment 
                  colspec  = {X[l] Q[c, si={table-format=-1.2{$^{***}$},
                                            input-open-uncertainty =,
                                            input-close-uncertainty=,
                                            table-align-text-before=false}]},
                  row{1,Z} = {guard},
                  row{2-X} = {rowsep=0pt},
                  row{2}   = {abovesep=2pt},
                  row{even[3-X]} = {abovesep=1ex},
                  cell{even[1-W]}{1} = {r=2}{h},    % see manual,  page 14
                  row{X-Z} = {rowsep=1pt},
                }
    \toprule
                                    &   Initiate conflict   \\
    \midrule
First = female                      & -0.08                 \\
                                    & (0.05)                \\
Second = prefer not to say          & -0.21                 \\
                                    & (0.18)                \\
Third = non-binary/ non-conforming  & -0.18                 \\
                                    & (0.12)                \\
(Intercept)                         & 0.35\TblrNote{***}    \\
                                    & (0.03)                \\
    \specialrule{dashed, fg=gray}{3pt}{3pt}
R$^2$                               & 0.01                  \\
Adj.\ R$^2$                         & 0.01                  \\
Number of observations              & 404                   \\
    \bottomrule
\end{talltblr}

\end{document}

在此处输入图片描述

编辑:被认为是@Mico 的评论。

答案3

正在寻找类似的东西?

在此处输入图片描述

\documentclass{standalone}
\usepackage{tabularx} % add tabularx package
\usepackage{booktabs} % add booktabs package for nicer horizontal rules
\begin{document}
%   \begin{table}
    \begin{tabularx}{0.7\textwidth}{>{\raggedright\arraybackslash}X>{\raggedleft\arraybackslash}X}
        \toprule
        & Initiate conflict \\
        \midrule
        First = female & $-0.08$ \\
        & $(0.05)$ \\
        Second = prefer not to say & $-0.21$ \\
        & $(0.18)$ \\
        Third = non-binary/non-conforming & $-0.18$ \\
        & $(0.12)$ \\
        (Intercept) & $0.35^{***}$ \\
        & $(0.03)$ \\
        \midrule
        R$^2$ & $0.01$ \\
        Adj. R$^2$ & $0.01$ \\
        Num. obs. & $404$ \\
        \bottomrule
    \end{tabularx}
%   \end{table}
\end{document}

稍后您可以在 Word 文档中插入标题

答案4

我个人会将值与不确定性合并到一行中。我觉得这样读起来更清晰。此外,由于以这种方式解析不确定性,因此如果您添加到设置中siunitx,可以使用替代格式。separate-uncertainty

下面的代码也使用threeparttable(灵感来自米科的答案)以便堆叠两个单独的表并保持不包括不确定性的居中对齐。

\documentclass[margin=2.5mm]{standalone}
\usepackage{array}
\usepackage{threeparttable}
\usepackage{booktabs}
\usepackage{siunitx}

\sisetup{
  uncertainty-mode=full,
  uncertainty-separator=\,,
  table-column-width=2.4cm,
}


\begin{document}
\begin{threeparttable}
  \begin{tabular}{p{6cm} S[table-format=-1.2(1)]}
    \toprule
    & {\clap{Initiate conflict}} \\
    \midrule
    First = female                    & -0.08(0.05) \\
    Second = prefer not to say        & -0.21(0.18) \\
    Third = non-binary/non-conforming & -0.18(0.12) \\
    (Intercept)                       &  0.35(0.03)$^{***}$ \\
  \end{tabular}

  \vspace{\dimexpr6pt-\lineskip}%
  \begin{tabular}{p{6cm} S[table-format=-1.2]}
    R$^2$                             & 0.01 \\
    Adj. R$^2$                        & 0.01 \\
    Num. obs.                         & {$\phantom{-}404$} \\
    \midrule
    \multicolumn{2}{l}{\scriptsize{$^{***}p<0.001$; $^{**}p<0.01$; $^{*}p<0.05$}}
  \end{tabular}
\end{threeparttable}
\end{document}

在此处输入图片描述

相关内容