[Tex/LaTex] Beamer Table Alignment

beamerhorizontal alignmenttables

I am wondering how to delete the empty space on the right side of the last column. Also, is there any way to align Panel A and B in beamer?

%\documentclass[handout,table,slidestop,compress,mathserif, 10pt]{beamer}
    \documentclass[table,slidestop,compress,mathserif, 10pt]{beamer}
    \usepackage{array}
    \usepackage{verbatim}
    \usepackage{subfigure}
    \usepackage{amsmath}
    \usepackage{tabularx}
    \usepackage{booktabs,dcolumn}
    \usetheme{Frankfurt}
    %\usetheme{CambridgeUS}
    \usecolortheme{seahorse}
    \setbeamersize{text margin left=10mm, text margin right=7mm}
    \usepackage{pstricks}
    \usepackage{colortab}
    \usepackage{tikz}
    \usetikzlibrary{calc}
    \usepackage{bbm}
    \usepackage{amssymb}
    \usepackage{amsmath}
    \usepackage{amsfonts}
    \usetikzlibrary{decorations.pathreplacing}
    \usetikzlibrary{decorations.pathmorphing}
    \newcommand{\sumframe}[2]{\psframebox*[fillcolor=sumcolor,border=.5pt,bordercolor=black,shadow=true,shadowcolor=gray]{%
    \parbox[c]{#1}{#2}}}%
    \usepackage{xcolor}

    \usepackage[orientation=landscape,size=custom,width=16,height=9,scale=0.5,debug]{beamerposter} 


    \newcommand{\indicator}[1]{\mathbbm{1}_{\left[ {#1} \right] }}
    \usepackage{scalerel,stackengine}
    \stackMath
    \newcommand\reallywidehat[1]{%
    \savestack{\tmpbox}{\stretchto{%
      \scaleto{%
        \scalerel*[\widthof{\ensuremath{#1}}]{\kern-.6pt\bigwedge\kern-.6pt}%
        {\rule[-\textheight/2]{1ex}{\textheight}}%WIDTH-LIMITED BIG WEDGE
      }{\textheight}% 
    }{0.5ex}}%
    \stackon[1pt]{#1}{\tmpbox}%
    }
    \newcommand{\tikzmark}[1]{\tikz[overlay,remember picture] \node (#1) {};}


    \definecolor{dgreen}{rgb}{0.,0.6,0.}
    \definecolor{dblue}{rgb}{0.,0.,0.6}
    \definecolor{dred}{rgb}{0.6,0.,0.}



    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


    \title[Title]
    {
      {\fontsize{16}{16}\selectfont Title} \\ 
    }



    \author[Name]
    {%
      \texorpdfstring{
          \centering
          Name\\
      }
      {Name}
    }


    \date[September 7, 2017]
    {September 7, 2017}




    % The main document

    \begin{document}
    \begin{frame}
    \maketitle
    \end{frame}





    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    \setcounter{subsection}{6}
    \begin{frame}[label=Survivorship_Result2b]{Subsample test}
    \vspace{-.53cm}
    \begin{table}[htb]
    \footnotesize   
        \begin{tabularx}{\linewidth}{l*{5}{Y}}
        \toprule
        \multicolumn{5}{l}{\textbf{Panel A: Group A}} \\
        \midrule
       & \textbf{(1)} & \textbf{(2)} & \textbf{(3)}& \textbf{(4)} & \textbf{(5)}  \\\hline 


    \tikzmark{newcolr}{\textbf{A $\cdot$ B} &\ 0.006& 0.006 &0.006&0.006&0.005  \\
    &\ [4.05]&[2.58]&[3.29]&[3.06]&[4.06]}\\
    \textbf{A} &-0.004& -0.003 & -0.003&-0.003 &-0.003   \\
    &[-6.81]&[-3.49] &[-4.10] &[-3.05]&[-3.35]\\

    \textbf{B} &  &&-0.002&-0.002 \\
    &&& [-1.60]& [-1.55] \\\hline


      \end{tabularx} 
      \begin{tabularx}{\linewidth}{l*{5}{Y}}
        \toprule 
        \multicolumn{5}{l}{\textbf{Panel B: Group X}} \\
        \midrule
       & \textbf{(1)} & \textbf{(2)} & \textbf{(3)}& \textbf{(4)} & \textbf{(5)}  \\\hline 

    \tikzmark{colorsa}{\textbf{X $\cdot$ Y} &\ 0.003& 0.002 &0.002&0.002&0.002  \\
    &\ [1.44]&[1.28]&[1.40]&[1.32]&[1.24]}\\
    \textbf{X} &-0.001& 0.000 & 0.000&0.000 &-0.001   \\
    &[-1.67]&[0.04] &[0.04] &[0.04]&[-1.08]\\
    \textbf{Y} &  &&-0.001&-0.001 \\
    &&& [-1.06]& [-1.00]\\ 

    \textbf{Controls}& No& Yes & Yes & Yes & Yes  \\
    \textbf{Group FEs}& Yes& Yes & No & No & Yes  \\
    \textbf{Family FEs}& No& No & Yes & Yes & No  \\
    \textbf{Individual FEs}& No& No & No & Yes & No  \\
    \textbf{Family-Individual Clustering}& Yes& Yes & Yes & Yes& Yes \\
    \textbf{Observations}&8,895&7,654&7,654& 7,654&4,538  \\
    \textbf{R-squared} &0.48&0.53&0.40&0.41 &0.54 \\\hline
        \bottomrule
      \end{tabularx}
    \end{table}

    \tikz[overlay,remember picture]{\draw[draw=red,thick,single,fill opacity=0.2] ($(colorsa)+(-0.19,0.28)$) rectangle ($(colorsa)+(11.9,-0.55)$);}

    \tikz[overlay,remember picture]{\draw[draw=blue,thick,single,fill opacity=0.2] ($(newcolr)+(-0.19,0.28)$) rectangle ($(newcolr)+(11.9,-0.55)$);}


    \end{frame}





    \end{document} 

Best Answer

I would redesign your table as follows:

  • reordered code in editor such that, already in it, the code mimics the table structure. With this it is simpler to discover all missing parts of code
  • merge both tables in one
  • remove superfluous rules
  • use only rules defined in package booktabs
  • make your mwe works
    1. remove \tikzmark stuff (seems to be wrongly used)
    2. instead frame around rows use \rowcolor
    3. remove superfluous packages in preamble (like colorab, xcolor; both are loaded by beamer using option table ...)
  • replace unknown column type Y with S defined in package siunitx
  • in mwe consider only relevant packages and frame

this effort resulted with:

enter image description here

\documentclass[table,slidestop,compress,mathserif, 10pt]{beamer}
\usetheme{Frankfurt}
\usecolortheme{seahorse}
\setbeamersize{text margin left=10mm, text margin right=7mm}

\usepackage{array, booktabs, tabularx}
\newcommand\mcx[1]{\multicolumn{1}{>{\centering\arraybackslash}X}{\textbf{#1}}}
\setlength\aboverulesep{1pt}
\setlength\belowrulesep{1pt}
\usepackage{siunitx}

\begin{document}
\begin{frame}[fragile]
\frametitle{Subsample test}
\label{tab:SR-2b}
    \scriptsize%footnotesize
    \renewcommand\arraystretch{1.1}
    \begin{tabularx}{\linewidth}{%
            >{\bfseries}l
            *{6}{S[detect-mode,
                   %input-symbols =  ()[] ,
                   table-space-text-pre ={(},
                   table-space-text-post={)},
                  table-align-text-pre =false,
                  table-align-text-post=false,
                   table-format=-1.3]}
                    }
        \toprule
\multicolumn{6}{l}{\textbf{Panel A: Group A}}                       \\
        \midrule
    & \mcx{(1)} & \mcx{(2)} & \mcx{(3)} & \mcx{(4)} & \mcx{(5)}     \\
        \midrule
\rowcolor{blue!20}
A $\cdot$ B
    &  0.006    &  0.006    &  0.006    &  0.006    &  0.005        \\
\rowcolor{blue!20}
    & [4.05]    & [2.58]    & [3.29]    & [3.06]    & [4.06]        \\
    \addlinespace[2pt]
A   &  -0.004   &  -0.003   &  -0.003   &  -0.003   &  -0.003       \\
    & [-6.81]   & [-3.49]   & [-4.10]   & [-3.05]   & [-3.35]       \\
    \addlinespace[2pt]
B   &           &           &  -0.002   &  -0.002   &               \\
    &           &           & [-1.60]   & [-1.55]   &               \\
    \midrule
\multicolumn{6}{l}{\textbf{Panel B: Group X}}                       \\
    \midrule
\rowcolor{red!30}
X $\cdot$ Y
    &  0.003    &  0.002    &  0.002    &  0.002    &  0.002        \\
\rowcolor{red!30}
    & [1.44]    & [1.28]    & [1.40]    & [1.32]    & [1.24]        \\
    \addlinespace[2pt]
X   &  -0.001   &  0.000    &  0.000    &  0.000    &  -0.001       \\
    & [-1.67]   & [0.04]    & [0.04]    & [0.04]    & [-1.08]       \\
Y   &           &           & -0.001    & -0.001    &               \\
    &           &           & [-1.06]   & [-1.00]   &               \\
    \midrule
Controls
    & {No}      & {Yes}     & {Yes}     & {Yes}     & {Yes}         \\
Group FEs
    & {Yes}     & {Yes}     & {No}      & {No}      & {Yes}         \\
Family FEs
    & {No}      & {No}      & {Yes}     & {Yes}     & {No}          \\
Individual FEs
    & {No}      & {No}      & {No}      & {Yes}     & {No}          \\
Family-Individual Clustering
    & {Yes}     & {Yes}     & {Yes}     & {Yes}     & {Yes}         \\
Observations
    & 8,895     & 7,654     & 7,654     & 7,654     & 4,538         \\
R-squared
    & 0.48      & 0.53      & 0.40      & 0.41      & 0.54          \\
    \bottomrule
    \end{tabularx}
\end{frame}
\end{document}

After that result in case that the rectangles around now colored rows are required for some reason, i would investigate how to properly use tikzmark for drawing them.

I guess that frames around rows should be as show next image. for it some changes to above mwe are done. indicated are with % <---:

enter image description here

To obtain above image of table the mwe had to be compiled at least twice.

\documentclass[table,10pt]{beamer}
\usetheme{Frankfurt}
\usecolortheme{seahorse}
\setbeamersize{text margin left=10mm, text margin right=7mm}

\usepackage{array, booktabs, tabularx}
\newcommand\mcx[1]{\multicolumn{1}{>{\centering\arraybackslash}X}{\textbf{#1}}}
\setlength\aboverulesep{1pt}
\setlength\belowrulesep{1pt}
\usepackage{siunitx}

\usepackage{tikz}                % <-------
\usetikzlibrary{calc, tikzmark}  % <-------

\begin{document}
\begin{frame}[fragile]
\frametitle{Subsample test}
\label{tab:SR-2b}
    \scriptsize%footnotesize
    \renewcommand\arraystretch{1.1}
    \begin{tabularx}{\linewidth}{%
            >{\bfseries}l
            *{6}{S[detect-mode,
                   %input-symbols =  ()[] ,
                   table-space-text-pre ={(},
                   table-space-text-post={)},
                  table-align-text-pre =false,
                  table-align-text-post=false,
                   table-format=-1.3]}
                    }
        \toprule
\multicolumn{6}{l}{\textbf{Panel A: Group A}}                       \\
        \midrule
    & \mcx{(1)} & \mcx{(2)} & \mcx{(3)} & \mcx{(4)} & \mcx{(5)}     \\
        \midrule
\tikzmark{a1}    % <-------
A $\cdot$ B
    &  0.006    &  0.006    &  0.006    &  0.006    &  0.005        \\
    & [4.05]    & [2.58]    & [3.29]    & [3.06]    & [4.06]\tikzmark{a2}   \\    % <-------
    \addlinespace[2pt]
A   &  -0.004   &  -0.003   &  -0.003   &  -0.003   &  -0.003       \\
    & [-6.81]   & [-3.49]   & [-4.10]   & [-3.05]   & [-3.35]       \\
    \addlinespace[2pt]
B   &           &           &  -0.002   &  -0.002   &               \\
    &           &           & [-1.60]   & [-1.55]   &               \\
    \midrule
\multicolumn{6}{l}{\textbf{Panel B: Group X}}                       \\
    \midrule
\tikzmark{b1}   % <-------
 X $\cdot$ Y
    &  0.003    &  0.002    &  0.002    &  0.002    &  0.002        \\
    & [1.44]    & [1.28]    & [1.40]    & [1.32]    & [1.24]\tikzmark{b2}   \\    % <-------
    \addlinespace[2pt]
X   &  -0.001   &  0.000    &  0.000    &  0.000    &  -0.001       \\
    & [-1.67]   & [0.04]    & [0.04]    & [0.04]    & [-1.08]       \\
Y   &           &           & -0.001    & -0.001    &               \\
    &           &           & [-1.06]   & [-1.00]   &               \\
    \midrule
Controls
    & {No}      & {Yes}     & {Yes}     & {Yes}     & {Yes}         \\
Group FEs
    & {Yes}     & {Yes}     & {No}      & {No}      & {Yes}         \\
Family FEs
    & {No}      & {No}      & {Yes}     & {Yes}     & {No}          \\
Individual FEs
    & {No}      & {No}      & {No}      & {Yes}     & {No}          \\
Family-Individual Clustering
    & {Yes}     & {Yes}     & {Yes}     & {Yes}     & {Yes}         \\
Observations
    & 8,895     & 7,654     & 7,654     & 7,654     & 4,538         \\
R-squared
    & 0.48      & 0.53      & 0.40      & 0.41      & 0.54          \\
    \bottomrule
    \end{tabularx}

\tikzset{frameline/.style = {draw=#1, thick, inner sep=2pt}} % <-------
\begin{tikzpicture}[overlay,remember picture]                % <-------
\draw[frameline=blue] ($({pic cs:a1})+(-2ex,0.8em)$)         % <-------
    rectangle ($({pic cs:a2})+(3ex,-1ex)$);                  % <-------
\draw[frameline=red] ($({pic cs:b1})+(-2ex,0.8em)$)          % <-------
    rectangle ($({pic cs:b2})+(3ex,-1ex)$);                  % <------- 
\end{tikzpicture}                                            % <-------

\end{frame}
\end{document}
Related Question