2

Question:

I have been preparing beamer presentation which is in last stage where I wish to insert a long table but unfortunately I couldn't find the solution. Please guide me.. Please...

Thanks in advance........

MWE:

\documentclass[12pt]{beamer}
\usepackage{ragged2e}\justifying
\usepackage{xcolor}
\usepackage{hyperref}
\usetheme{AnnArbor}
%%================================
\usepackage[f]{esvect}
\usecolortheme{beaver}% red color theme
\usefonttheme{professionalfonts} % using non standard fonts for beamer
%%----------------------------------------------------------
\usepackage{makecell, multirow}
\usepackage{siunitx}
\usepackage{etoolbox}
\newrobustcmd\B{\DeclareFontSeriesDefault[rm]{bf}{b}\bfseries}
%%-----------------------------------------------------------
\usepackage[skip=1ex, font=small, labelfont=bf]{caption}
\usefonttheme{serif} % default family is serif
\usepackage{setspace}
\usepackage{lipsum}
\addtobeamertemplate{frametitle}{}{\vspace{-0.4em}} % decrease
\setlength{\parskip}{5pt}
\title[]{\footnotesize{\textbf{My Title}}}
\subtitle{}
\author[]{}
\institute[]{}
\date[]{\textbf{\today}}
%%=================
\begin{document}
\begin{frame}[plain, noframenumbering]
 \maketitle  
\end{frame}
%%------------------------------------------------------------
\begin{frame}[t]{}
\begin{table}[ht]
    \centering
\sisetup{detect-weight,
         mode=text}
    \setcellgapes{5pt}
    \makegapedcells
\caption{My table}
\label{tab:...}
    \label{tab:my-table}
\begin{tabular}{|*{5}{S[table-format=1.1]|}
                 *{2}{S[table-format=-1.11]|}
                 }
\hline
{\multirow{2.4}{*}{A}} & {\multirow{2.4}{*}{B}} & {\multirow{2.4}{*}{C}} & {\multirow{2.4}{*}{D}} & {\multirow{2.4}{*}{E}} & \multicolumn{2}{c|}{F}         \\ \cline{6-7}
        &       &       &       &       & {G}           & {H}           \\  \hline
\B  0.2 &\B 0.5 &\B 1   &\B 0.2 &\B 0.5 & -1.8713360906 & -1.7640262021 \\ \hline
\B  0.3 & 0.5   & 1     & 0.2   & 0.5   & -1.9365758323 & -1.7648755545 \\ \hline
\B  0.4 & 0.5   & 1     & 0.2   & 0.5   & -1.9844365775 & -1.7572640364 \\ \hline
0.2     &\B 0.6 & 1     & 0.2   & 0.5   & -1.8893451634 & -1.7769110253 \\ \hline
0.2     &\B 0.7 & 1     & 0.2   & 0.5   & -1.9037201042 & -1.7845630194 \\ \hline
0.2     &\B 0.8 & 1     & 0.2   & 0.5   & -1.9084283289 & -1.78054097011    \\ \hline
0.2     & 0.5   &\B 1.1 & 0.2   & 0.5   & -1.8638586434 & -1.75716821872    \\ \hline
0.2     & 0.5   &\B 1.2 & 0.2   & 0.5   & -1.8563791180 & -1.75030388119    \\ \hline
0.2     & 0.5   &\B 1.3 & 0.2   & 0.5   & -1.8488975550 & -1.74343325690    \\ \hline
0.2     & 0.5   & 1     &\B 0.3 & 0.5   & -1.7816929512 & -1.67995077275    \\ \hline
0.2     & 0.5   & 1     &\B 0.4 & 0.5   & -1.6940695909 & -1.59754625788    \\ \hline
0.2     & 0.5   & 1     &\B 0.5 & 0.5   & -1.60833298231& -1.51669912930    \\ \hline
0.2     & 0.5   & 1     & 0.2   &\B 0.6 & -1.79104380621& -1.69665633242    \\ \hline
0.2     & 0.5   & 1     & 0.2   &\B 0.7 & -1.72028938675& -1.63324789889    \\ \hline
0.2     & 0.5   & 1     & 0.2   &\B 0.8 & -1.66248454886& -1.58021088372    \\ \hline
\end{tabular}
    \end{table}
\end{frame}
%%------------------------------------------------------------
\end{document}

2 Answers 2

2

Another possible solution is use for table the tabularray package. Its use has a some specifics, hence a new answer.

Using tabularray a text in column headers, when it contain letters d, D, e or E, interact with S specification and throw an error. This can be solved on two ways:

  • if numbers in tables not contain exponents (like 12.34e-6), than you can remove from S column specifications those exponent markers by option input-exponent-markers= (as is used in MWE below)
  • another way (more recommended) is encapsulate column header in two curly braces. for example \SetCell[r=2]{c} {{D}} or \SetCell[c=2]{c} {{E}}.

In the first case the MWE is:

\documentclass[12pt]{beamer}
\usetheme{AnnArbor}
\usecolortheme{beaver}% red color theme
\usefonttheme{professionalfonts} % using non standard fonts for beamer
\usefonttheme{serif} % default family is serif
%----
    \setbeamerfont{title page}{size=\small\bfseries}
    \setbeamerfont{subtitle}{size=\scriptsize\bfseries}
%----
    \setbeamerfont{frametitle}{size=\footnotesize\bfseries}
%----
    \setbeamertemplate{caption}[numbered]
\usepackage[font=scriptsize,
            labelfont={bf,color=blue}]
            {caption}% it is compatible with the last beamer versions
%---------------------------------------------------------------%
\usepackage{ragged2e}\justifying
\usepackage{tabularray}
\UseTblrLibrary{siunitx}

\setlength{\parskip}{5pt}
\usepackage{etoolbox}
\newrobustcmd\B{\DeclareFontSeriesDefault[rm]{bf}{b}\bfseries\color{teal}}
\AtBeginEnvironment{table}{\setlength{\parskip}{-5pt}}
%---------------------------------------------------------------%
\usepackage{lipsum}

\title[Presentation title]{Presentation title}
\subtitle{Example of use the \texttt{tabularray} package}
\author[zfc]{Math-Man}
\institute[]{}
\date{\today}
%---------------------------------------------------------------%

\begin{document}
\begin{frame}[plain, noframenumbering]
    \maketitle
\end{frame}

%---------------------------------------------------------------%
\section{Result}
\subsection{Simulations}
%---------------------------------------------------------------%

\begin{frame}[t]% no frame title
\begin{table}
    \centering
\sisetup{detect-weight,
         mode=text,
         input-exponent-markers=}   % <===
\caption{My table}
\label{tab:tblr}
    \footnotesize
\begin{tblr}{hlines, vlines,
             colspec={*{5}{ S[table-format=1.1] }
                      *{2}{ S[table-format=-1.11]} },
             colsep=4pt,
             abovesep={ 0.5pt},     % <---
             belowsep={-0.5pt}      % <---
                 }
\SetCell[r=2]{c} A
        &   \SetCell[r=2]{c} B
                &   \SetCell[r=2]{c} C
                        &   \SetCell[r=2]{c} D
                                &   \SetCell[r=2]{c} E
                                        &   \SetCell[c=2]{c} F
                                                        &                   \\
        &       &       &       &       &   {{{G}}}     &   {{{H}}}         \\
\B  0.2 &\B 0.5 &\B 1   &\B 0.2 &\B 0.5 & -1.8713360906 & -1.7640262021     \\
\B  0.3 & 0.5   & 1     & 0.2   & 0.5   & -1.9365758323 & -1.7648755545     \\
\B  0.4 & 0.5   & 1     & 0.2   & 0.5   & -1.9844365775 & -1.7572640364     \\
0.2     &\B 0.6 & 1     & 0.2   & 0.5   & -1.8893451634 & -1.7769110253     \\
0.2     &\B 0.7 & 1     & 0.2   & 0.5   & -1.9037201042 & -1.7845630194     \\
0.2     &\B 0.8 & 1     & 0.2   & 0.5   & -1.9084283289 & -1.78054097011    \\
0.2     & 0.5   &\B 1.1 & 0.2   & 0.5   & -1.8638586434 & -1.75716821872    \\
0.2     & 0.5   &\B 1.2 & 0.2   & 0.5   & -1.8563791180 & -1.75030388119    \\
0.2     & 0.5   &\B 1.3 & 0.2   & 0.5   & -1.8488975550 & -1.74343325690    \\
0.2     & 0.5   & 1     &\B 0.3 & 0.5   & -1.7816929512 & -1.67995077275    \\
0.2     & 0.5   & 1     &\B 0.4 & 0.5   & -1.6940695909 & -1.59754625788    \\
0.2     & 0.5   & 1     &\B 0.5 & 0.5   & -1.60833298231& -1.51669912930    \\
0.2     & 0.5   & 1     & 0.2   &\B 0.6 & -1.79104380621& -1.69665633242    \\
0.2     & 0.5   & 1     & 0.2   &\B 0.7 & -1.72028938675& -1.63324789889    \\
0.2     & 0.5   & 1     & 0.2   &\B 0.8 & -1.66248454886& -1.58021088372    \\
\end{tblr}
    \end{table}
\end{frame}
\end{document}

in the second case the table preamble and column headers are:

\begin{table}
    \centering
\sisetup{detect-weight,
         mode=text} 
\caption{My table}
\label{tab:tblr}
    \footnotesize
\begin{tblr}{hlines, vlines,
             colspec={*{5}{ S[table-format=1.1] }
                      *{2}{ S[table-format=-1.11]} },
             colsep=4pt,
             abovesep={ 0.5pt},     % <---
             belowsep={-0.5pt}      % <---
                 }
\SetCell[r=2]{c} A
        &   \SetCell[r=2]{c} B
                &   \SetCell[r=2]{c} C
                        &   \SetCell[r=2]{c} {{D}}  % <---
                                &   \SetCell[r=2]{c} {{E}}  % <---
                                        &   \SetCell[c=2]{c} F
                                                        &                   \\
        &       &       &       &       &   {{{G}}}     &   {{{H}}}         \\

In both cases result of compilation are the same:

enter image description here

Note: In comparison to the first answer here in table are used bigger font size, i.e. instead \scriptsize is used \footnotesize.

1
  • Many thanks for excellent information. once again thank you so much for help.
    – SandyM
    Commented Sep 2, 2021 at 18:15
8
  • do you really need table in your presentation? For audience it is boring usually :-(
  • that your table can be fit in one frame, you need reduce font size and replace \setcellgapes{5pt}\makegapedcells by \setlength\extrarowheight{1pt}:

Edit:

  • The cause of bigger space after caption is your settings of distance between paragraph: \setlength{\parskip}{5pt} which insert additional vertical of 5pt space also between caption and table. This can be resolved on the following ways:
    • not use this settings (I don't see any reason for it)
    • locally, in each table, change it to \setlength{\parskip}{-5pt} or this do globally by use etoolbox package with macro \AtBeginEnvironment{table}{\setlength{\parskip}{-5pt}}
    • by use of combination beamer caption mechanism and caption package (versions of the beamerpackage after 2019 to some extent allow cooperation between thebeamerandcaption` packages). This combination is used in MWE below
\setbeamertemplate{caption}[numbered]
\usepackage[font=scriptsize, 
            labelfont={bf,color=blue}]
            {caption}% it is compatible with beamers
  • for font size of the pagetitle and frametitle rather use \setbeamerfont{<object name>}{size=...} than adjust them locally (see MWE below)

enter image description here

\documentclass[12pt]{beamer}
\usetheme{AnnArbor}
\usecolortheme{beaver}% red color theme
\usefonttheme{professionalfonts} % using non standard fonts for beamer
\usefonttheme{serif} % default family is serif
%----
    \setbeamerfont{title page}{size=\footnotesize\bfseries}
%----
    \setbeamerfont{frametitle}{size=\footnotesize\bfseries}
%----
    \setbeamertemplate{caption}[numbered]
\usepackage[font=scriptsize, 
            labelfont={bf,color=blue}]
            {caption}% it is compatible with beamers
%%----------------------------------------------------------
\usepackage{ragged2e}\justifying
\usepackage[f]{esvect}
\usepackage{makecell, multirow}
\usepackage{siunitx}
%\usepackage{xcolor}        % it is loaded by beamer
%\usepackage{hyperref}      % it is loaded by beamer

\setlength{\parskip}{5pt}
\usepackage{etoolbox}
\newrobustcmd\B{\DeclareFontSeriesDefault[rm]{bf}{b}\bfseries}
\AtBeginEnvironment{table}{\setlength{\parskip}{-5pt}}
%%-----------------------------------------------------------
%\usepackage{setspace}
\usepackage{lipsum}

\title[Presentation title]{Presentation title}
\subtitle{}
\author[Math-Man]{Math-Man}
\institute[]{}
\date[]{\textbf{\today}}
%%=================
\begin{document}
\begin{frame}[plain, noframenumbering]
 \maketitle
\end{frame}
%%------------------------------------------------------------

\begin{frame}[t]{}
\begin{table}[ht]
    \centering
\sisetup{detect-weight,
         mode=text}
    \setlength\extrarowheight{1pt}
\caption{My table}
\label{tab:...}
    \scriptsize
\begin{tabular}{|*{5}{S[table-format=1.1]|}
                 *{2}{S[table-format=-1.11]|}
                 }
\hline
{\multirow{2.4}{*}{A}} & {\multirow{2.4}{*}{B}} & {\multirow{2.4}{*}{C}} & {\multirow{2.4}{*}{D}} & {\multirow{2.4}{*}{E}} & \multicolumn{2}{c|}{F}         \\ \cline{6-7}
        &       &       &       &       & {G}           & {H}           \\  \hline
\B  0.2 &\B 0.5 &\B 1   &\B 0.2 &\B 0.5 & -1.8713360906 & -1.7640262021 \\ \hline
\B  0.3 & 0.5   & 1     & 0.2   & 0.5   & -1.9365758323 & -1.7648755545 \\ \hline
\B  0.4 & 0.5   & 1     & 0.2   & 0.5   & -1.9844365775 & -1.7572640364 \\ \hline
0.2     &\B 0.6 & 1     & 0.2   & 0.5   & -1.8893451634 & -1.7769110253 \\ \hline
0.2     &\B 0.7 & 1     & 0.2   & 0.5   & -1.9037201042 & -1.7845630194 \\ \hline
0.2     &\B 0.8 & 1     & 0.2   & 0.5   & -1.9084283289 & -1.78054097011    \\ \hline
0.2     & 0.5   &\B 1.1 & 0.2   & 0.5   & -1.8638586434 & -1.75716821872    \\ \hline
0.2     & 0.5   &\B 1.2 & 0.2   & 0.5   & -1.8563791180 & -1.75030388119    \\ \hline
0.2     & 0.5   &\B 1.3 & 0.2   & 0.5   & -1.8488975550 & -1.74343325690    \\ \hline
0.2     & 0.5   & 1     &\B 0.3 & 0.5   & -1.7816929512 & -1.67995077275    \\ \hline
0.2     & 0.5   & 1     &\B 0.4 & 0.5   & -1.6940695909 & -1.59754625788    \\ \hline
0.2     & 0.5   & 1     &\B 0.5 & 0.5   & -1.60833298231& -1.51669912930    \\ \hline
0.2     & 0.5   & 1     & 0.2   &\B 0.6 & -1.79104380621& -1.69665633242    \\ \hline
0.2     & 0.5   & 1     & 0.2   &\B 0.7 & -1.72028938675& -1.63324789889    \\ \hline
0.2     & 0.5   & 1     & 0.2   &\B 0.8 & -1.66248454886& -1.58021088372    \\ \hline
\end{tabular}
    \end{table}
\end{frame}
%%------------------------------------------------------------
\end{document}
5
  • Why my code not compile, I made change according to your comments
    – SandyM
    Commented Aug 30, 2021 at 6:08
  • Yes I do agree with comment that usually boring. Please share your code which produces above pic. Thanks for helping me.
    – SandyM
    Commented Aug 30, 2021 at 6:09
  • 1
    @Math-Man, done (I forgot to load code). BTW, you can upvote my answer too :-)
    – Zarko
    Commented Aug 30, 2021 at 6:21
  • How can I reduce blank space between caption and frame title. I mean I want to shift my table vertically.
    – SandyM
    Commented Aug 31, 2021 at 5:18
  • @Math-Man, see edited answer.
    – Zarko
    Commented Aug 31, 2021 at 9:32

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .