tikzpicture 去中心化表格内的输入表格?Beamer

tikzpicture 去中心化表格内的输入表格?Beamer

我正在输入一个表格,\begin{tikzpicture}以便能够使用协调器计算器,这样我就不必每次都指定它。我很头疼,因为它使表格不居中。如果没有 tikzpicture 吞没命令\input,表格将适合投影仪并居中。有了它,表格会向右移动,不适合幻灯片。

准确复制该问题的完整示例代码:

  \documentclass[10pt, aspectratio=169]{beamer}
    \usepackage[utf8]{inputenc}
    \usepackage{tikz}
    \usepackage{booktabs}
    \usepackage{threeparttable}
    \usepackage{float}
    \usetikzlibrary{arrows}
    \usetikzlibrary{shapes}
    \usetikzlibrary{plotmarks}
    \usetikzlibrary{calc}
    
    \begin{document}
    
    \begin{frame}
    
        \begin{table}[H]
            \begin{center}
                \scalebox{0.5}{
                    \begin{threeparttable}
                \begin{tikzpicture}
                    \node (table) {\begin{tabular}{l*{7}{c}}
    \toprule
                                    &\multicolumn{3}{c}{BLABLA}&\multicolumn{4}{c}{BLABLA}\\\cmidrule(lr){2-4}\cmidrule(lr){5-8}
                                    &\multicolumn{1}{c}{(1)}&\multicolumn{1}{c}{(2)}&\multicolumn{1}{c}{(3)}&\multicolumn{1}{c}{(4)}&\multicolumn{1}{c}{(5)}&\multicolumn{1}{c}{(6)}&\multicolumn{1}{c}{(7)}\\
                                    &\multicolumn{1}{c}{BLABLA}&\multicolumn{1}{c}{BLABLA}&\multicolumn{1}{c}{BLABLA}&\multicolumn{1}{c}{BLABLA}&\multicolumn{1}{c}{BLABLA}&\multicolumn{1}{c}{BLABLA}&\multicolumn{1}{c}{BLABLA}\\
    \midrule
    BLABLABLABLABLABLALBALBAL          &     0.01&     0.09&     0.07&     0.10&     0.14&     0.14&     0.14\\
                                    &   (0.03)&   (0.04)&   (0.03)&   (0.04)&   (0.05)&   (0.04)&   (0.05)\\
                                    &   [0.65]&   [0.01]&   [0.02]&   [0.01]&   [0.00]&   [0.00]&   [0.00]\\
    \addlinespace
    BLABLABLABLABLABLALBALBAL      &     0.01&     0.07&     0.07&     0.04&     0.05&    -0.01&    -0.03\\
                                    &   (0.02)&   (0.03)&   (0.03)&   (0.05)&   (0.05)&   (0.06)&   (0.04)\\
                                    &   [0.54]&   [0.02]&   [0.02]&   [0.36]&   [0.38]&   [0.91]&   [0.49]\\
    \addlinespace
    BLABLABLABLABLABLALBALBAL             &    -0.01&    -0.06&    -0.01&     0.04&    -0.03&    -0.02&     0.01\\
                                    &   (0.02)&   (0.03)&   (0.03)&   (0.03)&   (0.03)&   (0.04)&   (0.03)\\
                                    &   [0.60]&   [0.05]&   [0.78]&   [0.19]&   [0.32]&   [0.67]&   [0.85]\\
    \addlinespace
    BLABLABLABLABLABLALBALBAL  $\times$ &     0.03&    -0.05&    -0.02&     0.01&    -0.03&     0.01&    -0.03\\
    BLABLABLABLABLABLALBALBAL          &   (0.03)&   (0.04)&   (0.04)&   (0.05)&   (0.06)&   (0.06)&   (0.06)\\
                                    &   [0.27]&   [0.23]&   [0.69]&   [0.79]&   [0.64]&   [0.85]&   [0.65]\\
    \addlinespace
    BLABLABLABLABLABLALBALBAL $\times$ &     0.03&     0.10&     0.02&    -0.03&    -0.06&    -0.04&    -0.07\\
    BLABLABLABLABLABLALBALBAL              &   (0.03)&   (0.04)&   (0.04)&   (0.05)&   (0.05)&   (0.05)&   (0.05)\\
                                    &   [0.30]&   [0.01]&   [0.61]&   [0.59]&   [0.30]&   [0.43]&   [0.15]\\
    \midrule
    \bottomrule
    \end{tabular}};
                    \draw [red,ultra thick,rounded corners]
                      ($(table.south west) !.61! (table.north west)$)
                      rectangle 
                      ($(table.south east) !.77! (table.north east)$);
                    \end{tikzpicture}   
                    \end{threeparttable}
                }
            \end{center}
        \end{table}
        
        
    \end{frame}
    
    \begin{frame}
    
        \begin{table}[H]
            \begin{center}
                \scalebox{0.5}{
                    \begin{threeparttable}
                        \begin{tabular}{l*{7}{c}}
    \toprule
                                    &\multicolumn{3}{c}{BLABLA}&\multicolumn{4}{c}{BLABLA}\\\cmidrule(lr){2-4}\cmidrule(lr){5-8}
                                    &\multicolumn{1}{c}{(1)}&\multicolumn{1}{c}{(2)}&\multicolumn{1}{c}{(3)}&\multicolumn{1}{c}{(4)}&\multicolumn{1}{c}{(5)}&\multicolumn{1}{c}{(6)}&\multicolumn{1}{c}{(7)}\\
                                    &\multicolumn{1}{c}{BLABLA}&\multicolumn{1}{c}{BLABLA BLABLA}&\multicolumn{1}{c}{BLABLA}&\multicolumn{1}{c}{BLABLA}&\multicolumn{1}{c}{BLABLA}&\multicolumn{1}{c}{BLABLA}&\multicolumn{1}{c}{BLABLA}\\
    \midrule
    BLABLABLABLABLABLALBALBAL          &     0.01&     0.09&     0.07&     0.10&     0.14&     0.14&     0.14\\
                                    &   (0.03)&   (0.04)&   (0.03)&   (0.04)&   (0.05)&   (0.04)&   (0.05)\\
                                    &   [0.65]&   [0.01]&   [0.02]&   [0.01]&   [0.00]&   [0.00]&   [0.00]\\
    \addlinespace
    BLABLABLABLABLABLALBALBAL      &     0.01&     0.07&     0.07&     0.04&     0.05&    -0.01&    -0.03\\
                                    &   (0.02)&   (0.03)&   (0.03)&   (0.05)&   (0.05)&   (0.06)&   (0.04)\\
                                    &   [0.54]&   [0.02]&   [0.02]&   [0.36]&   [0.38]&   [0.91]&   [0.49]\\
    \addlinespace
    BLABLABLABLABLABLALBALBAL             &    -0.01&    -0.06&    -0.01&     0.04&    -0.03&    -0.02&     0.01\\
                                    &   (0.02)&   (0.03)&   (0.03)&   (0.03)&   (0.03)&   (0.04)&   (0.03)\\
                                    &   [0.60]&   [0.05]&   [0.78]&   [0.19]&   [0.32]&   [0.67]&   [0.85]\\
    \addlinespace
    BLABLABLABLABLABLALBALBAL  $\times$ &     0.03&    -0.05&    -0.02&     0.01&    -0.03&     0.01&    -0.03\\
    BLABLABLABLABLABLALBALBAL          &   (0.03)&   (0.04)&   (0.04)&   (0.05)&   (0.06)&   (0.06)&   (0.06)\\
                                    &   [0.27]&   [0.23]&   [0.69]&   [0.79]&   [0.64]&   [0.85]&   [0.65]\\
    \addlinespace
    BLABLABLABLABLABLALBALBAL $\times$ &     0.03&     0.10&     0.02&    -0.03&    -0.06&    -0.04&    -0.07\\
    BLABLABLABLABLABLALBALBAL              &   (0.03)&   (0.04)&   (0.04)&   (0.05)&   (0.05)&   (0.05)&   (0.05)\\
                                    &   [0.30]&   [0.01]&   [0.61]&   [0.59]&   [0.30]&   [0.43]&   [0.15]\\
    \midrule
    \bottomrule
    \end{tabular}
                    \end{threeparttable}
                }
            \end{center}
        \end{table}
        
        
    \end{frame}
    
    
    
    \end{document}

答案1

  • 正如评论中所讨论的那样,删除threeparttable包装器(无论如何,它在这里没有任何用处,因为没有\caption\tnote指令并且没有tablenotes环境)可以解决眼前的问题。

  • 由于beamer文档类正在使用中,您不妨也删除\begin{table}and\end{table}语句。在beamer文档中,tableandfigure环境不会做任何有用的事情,因为它们不“浮动”(在 LaTeX 特定意义上)。

  • 我还会\scalebox{0.5}{...}用and语句进行替换\resizebox{\textwidth}{!}{...},并删除它们。\begin{center}\end{center}

  • 如果您使用指令来提供相当于表格标题的功能,那么您的基于 的演讲的听众beamer可能会很感激。\frametitle

  • 分别地,不管无论您使用哪种文档类,请摆脱大量的\multicolumn{1}{c}{...}包装器。例如,请替换

    &\multicolumn{1}{c}{(1)}&\multicolumn{1}{c}{(2)}&\multicolumn{1}{c}{(3)}&\multicolumn{1}{c}{(4)}&\multicolumn{1}{c}{(5)}&\multicolumn{1}{c}{(6)}&\multicolumn{1}{c}{(7)}\\
    

    更加易于阅读和调试

    & (1) & (2) & (3) & (4) & (5) & (6) & (7) \\
    

在此处输入图片描述

\documentclass[10pt, aspectratio=169]{beamer}
%% \usepackage[utf8]{inputenc} % that's the default nowadays
\usepackage{tikz}
\usetikzlibrary{arrows,shapes,plotmarks,calc}
\usepackage{booktabs}

\begin{document}
    
\begin{frame}
\frametitle{Provide a table caption here}
\resizebox{\textwidth}{!}{%  % better to use `\resizebox` than `\scalebox` here
    \begin{tikzpicture}
    \node (table) {%
    \begin{tabular}{@{} l *{7}{c} @{}}
    \toprule
        & \multicolumn{3}{c}{BLABLA} & \multicolumn{4}{c@{}}{BLABLA} \\
        \cmidrule(lr){2-4} \cmidrule(l){5-8}
        & (1) & (2) & (3) & (4) & (5) & (6) & (7) \\
        & BLABLA & BLABLA & BLABLA & BLABLA & BLABLA & BLABLA & BLABLA \\
    \midrule
    BLABLABLABLABLABLALBALBAL      &     0.01&     0.09&     0.07&     0.10&     0.14&     0.14&     0.14\\
        &   (0.03)&   (0.04)&   (0.03)&   (0.04)&   (0.05)&   (0.04)&   (0.05)\\
        &   [0.65]&   [0.01]&   [0.02]&   [0.01]&   [0.00]&   [0.00]&   [0.00]\\
    \addlinespace
    BLABLABLABLABLABLALBALBAL      &     0.01&     0.07&     0.07&     0.04&     0.05&    -0.01&    -0.03\\
        &   (0.02)&   (0.03)&   (0.03)&   (0.05)&   (0.05)&   (0.06)&   (0.04)\\
        &   [0.54]&   [0.02]&   [0.02]&   [0.36]&   [0.38]&   [0.91]&   [0.49]\\
    \addlinespace
    BLABLABLABLABLABLALBALBAL      &    -0.01&    -0.06&    -0.01&     0.04&    -0.03&    -0.02&     0.01\\
        &   (0.02)&   (0.03)&   (0.03)&   (0.03)&   (0.03)&   (0.04)&   (0.03)\\
        &   [0.60]&   [0.05]&   [0.78]&   [0.19]&   [0.32]&   [0.67]&   [0.85]\\
    \addlinespace
    BLABLABLABLABLABLALBALBAL $\times$ &     0.03&    -0.05&    -0.02&     0.01&    -0.03&     0.01&    -0.03\\
    BLABLABLABLABLABLALBALBAL          &   (0.03)&   (0.04)&   (0.04)&   (0.05)&   (0.06)&   (0.06)&   (0.06)\\
        &   [0.27]&   [0.23]&   [0.69]&   [0.79]&   [0.64]&   [0.85]&   [0.65]\\
    \addlinespace
    BLABLABLABLABLABLALBALBAL $\times$ &     0.03&     0.10&     0.02&    -0.03&    -0.06&    -0.04&    -0.07\\
    BLABLABLABLABLABLALBALBAL          &   (0.03)&   (0.04)&   (0.04)&   (0.05)&   (0.05)&   (0.05)&   (0.05)\\
        &   [0.30]&   [0.01]&   [0.61]&   [0.59]&   [0.30]&   [0.43]&   [0.15]\\
    \bottomrule
    \end{tabular}};

    \draw [red,ultra thick,rounded corners]
          ($(table.south west) !.61! (table.north west)$)
          rectangle 
          ($(table.south east) !.77! (table.north east)$);
    \end{tikzpicture}%   <-- don't forget this comment symbol
} % end of scope of \resizebox directive
\end{frame} 
\end{document}

相关内容