1

I have a long table as follows. I want to fit the table in a single frame.

I read the post on this site. But I can' t still achieve it. Could you help me?

     \documentclass[mathserif]{beamer}
    \usepackage[utf8]{inputenc}
    \usepackage[T1]{fontenc}
    \usepackage{lmodern}
    \usepackage[english]{babel}
    \usepackage{amsmath}
    \usepackage{amsfonts}
    \usepackage{amssymb}
    \usepackage{graphicx}
    \usetheme{Berlin}
    \usepackage{graphics} 
    \usepackage{times}
    \usepackage{amsmath} 
    \usepackage{tabularx} 
    \usepackage{longtable}
    \graphicspath{{figures/}}
    \usepackage{subfig}
    \usepackage{hyperref}
    \usepackage{cleveref}
    \PassOptionsToPackage{force}{filehook}
    \begin{document}
\begin{frame}[allowframebreaks]
    \begin{table}[hbt!]
    \begin{center}
    \begin{tabular}{|c|c|c|c|c|c|c|}\hline
    $x$&$t$&$U_{{\it numeric}} \left( x,t \right) $&$U_{{\it exact}} \left( x,t \right) $&${\it Error}$&${\it Refsolution}$&${\it RefError}$\\ \hlin\hline 
    $0$&$0$&$ 0.7938824$&$1$&$ 0.2061176$&$ 1.0$&$ 0.0\, \mathrm{E}^{+00}$ \\ \hline 
    $0$&$ 0.2$&$ 1.006211$&$ 0.9955687$&$ 0.0106423$&$ 0.9902$&$ 5.400\, \mathrm{E}^{-03}$ \\ \hline 
    $0$&$ 0.4$&$ 0.9876852$&$ 0.9824309$&$ 0.0052543$&$ 0.9627$&$ 1.980\, \mathrm{E}^{-02}$ \\ \hline 
    $0$&$ 0.6$&$ 0.9503579$&$ 0.9610430$&$ 0.0106851$&$ 0.9235$&$ 3.750\, \mathrm{E}^{-02}$ \\ \hline 
    $0$&$ 0.8$&$ 0.8949527$&$ 0.9321290$&$ 0.0371763$&$ 0.8827$&$ 4.950\, \mathrm{E}^{-02}$ \\ \hline 
    $0$&$ 1.0$&$ 0.8224107$&$ 0.8966296$&$ 0.0742189$&$ 0.8542$&$ 4.250\, \mathrm{E}^{-02}$ \\ \hline 
    $ 0.5$&$0$&$ 1.009713$&$ 0.9845362$&$ 0.0251768$&$ 0.9845$&$ 0.0\, \mathrm{E}^{+00}$ \\ \hline 
    $ 0.5$&$ 0.2$&$ 0.9953282$&$ 0.9966049$&$ 0.0012767$&$ 0.9994$&$ 2.800\, \mathrm{E}^{-03}$ \\ \hline 
    $ 0.5$&$ 0.4$&$ 0.9988702$&$ 0.9999306$&$ 0.0010604$&$ 0.9946$&$ 5.300\, \mathrm{E}^{-03}$ \\ \hline 
    $ 0.5$&$ 0.6$&$ 0.9953922$&$ 0.9943961$&$ 0.0009961$&$ 0.9734$&$ 2.100\, \mathrm{E}^{-02}$ \\ \hline 
    $ 0.5$&$ 0.8$&$ 0.9850632$&$ 0.9801960$&$ 0.0048672$&$ 0.9459$&$ 3.430\, \mathrm{E}^{-02}$ \\ \hline 
    $ 0.5$&$ 1.0$&$ 0.9683171$&$ 0.9578230$&$ 0.0104941$&$ 0.9316$&$ 2.620\, \mathrm{E}^{-02}$ \\ \hline 
    $ 1.0$&$0$&$ 0.940015$&$ 0.9400148$&$ 0.0000002$&$ 0.9400$&$ 0.0\, \mathrm{E}^{+00}$ \\ \hline 
    $ 1.0$&$ 0.2$&$ 0.9671292$&$ 0.9671279$&$ 0.0000013$&$ 0.9775$&$ 1.040\, \mathrm{E}^{-02}$ \\ \hline 
    $ 1.0$&$ 0.4$&$ 0.9865112$&$ 0.9865114$&$ 0.0000002$&$ 0.9974$&$ 1.090\, \mathrm{E}^{-02}$ \\ \hline 
    $ 1.0$&$ 0.6$&$ 0.9975042$&$ 0.9975042$&$ 0.0$&$ 0.9974$&$ 1.0\, \mathrm{E}^{-04}$ \\ \hline 
    $ 1.0$&$ 0.8$&$ 0.9997222$&$ 0.9997222$&$ 0.0$&$ 0.9801$&$ 1.960\, \mathrm{E}^{-02}$ \\ \hline 
    $ 1.0$&$ 1.0$&$ 0.9930872$&$ 0.9930876$&$ 0.0000004$&$ 0.9556$&$ 3.750\, \mathrm{E}^{-02}$ \\ \hline 
    \end{tabular}
    \end{center}
    \end{table}
\end{frame}
    \end{document}

2 Answers 2

3

Since the table material is supposed to fit in a single frame, I believe you need to switch to the \scriptsize relative font size.

I'd give the table a more open "look" by getting rid of all vertical lines and using far fewer, but well-spaced horizontal lines. I'd also use some of the machinery of the siunitx package to align the numbers on their respective decimal markers.

enter image description here

\documentclass[mathserif]{beamer}
    \usepackage[utf8]{inputenc}
    \usepackage[T1]{fontenc}
%%%    \usepackage{lmodern} % is overridden by 'times' package
    \usepackage[english]{babel}
    \usepackage{amsmath}
%%%    \usepackage{amsfonts} % is loaded automatically by 'amssymb' package
    \usepackage{amssymb}
    \usepackage{graphicx}
    \graphicspath{{figures/}}
%%%    \usepackage{graphics} % don't load both 'graphicx' and 'graphics'

    \usetheme{Berlin}
    \usefonttheme{professionalfonts}  
    \usepackage{newtxtext,newtxmath}
    \usepackage{booktabs,siunitx}
    
    \usepackage{amsmath} 
    \usepackage{tabularx} 
    \usepackage{longtable}
    \usepackage{subfig}
%%%    \usepackage{hyperref}  % is loaded automatically by 'beamer'
    \usepackage{cleveref}
    \PassOptionsToPackage{force}{filehook}
    
\begin{document}
\begin{frame}%[allowframebreaks]
\sisetup{group-digits=false}
    %\begin{table}[hbt!]
    %\begin{center}
\centering
\scriptsize
    \begin{tabular}{@{}
       *{2}{S[table-format=1.1]}
       *{3}{S[table-format=1.7]}
            S[table-format=1.4]
            S[table-format=1.3e-1]
       @{} }
    \toprule
    {$x$} & {$t$} & {$U_{\mathit{numeric}} ( x,t )$}  & {$U_{\mathit{exact}} ( x,t )$} 
    & {$\mathit{Error}$} & {$\mathit{RefSolution}$} & {$\mathit{RefError}$} \\ 
    \midrule
     0 & 0   & 0.7938824 &  1         &  0.2061176 & 1.0    &  0.0e+00   \\ 
     0 & 0.2 & 1.006211  &  0.9955687 &  0.0106423 & 0.9902 &  5.400e-03 \\ 
     0 & 0.4 & 0.9876852 &  0.9824309 &  0.0052543 & 0.9627 &  1.980e-02 \\ 
     0 & 0.6 & 0.9503579 &  0.9610430 &  0.0106851 & 0.9235 &  3.750e-02 \\ 
     0 & 0.8 & 0.8949527 &  0.9321290 &  0.0371763 & 0.8827 &  4.950e-02 \\ 
     0 & 1.0 & 0.8224107 &  0.8966296 &  0.0742189 & 0.8542 &  4.250e-02 \\ 
     \addlinespace
     0.5 & 0 & 1.009713  &  0.9845362 &  0.0251768 & 0.9845 &  0.0e+00   \\ 
     0.5 & 0.2&0.9953282 &  0.9966049 &  0.0012767 & 0.9994 &  2.800e-03 \\ 
     0.5 & 0.4&0.9988702 &  0.9999306 &  0.0010604 & 0.9946 &  5.300e-03 \\ 
     0.5 & 0.6&0.9953922 &  0.9943961 &  0.0009961 & 0.9734 &  2.100e-02 \\ 
     0.5 & 0.8&0.9850632 &  0.9801960 &  0.0048672 & 0.9459 &  3.430e-02 \\ 
     0.5 & 1.0&0.9683171 &  0.9578230 &  0.0104941 & 0.9316 &  2.620e-02 \\ 
     \addlinespace
     1.0 & 0  &0.940015  &  0.9400148 &  0.0000002 & 0.9400 &  0.0e+00   \\ 
     1.0 & 0.2&0.9671292 &  0.9671279 &  0.0000013 & 0.9775 &  1.040e-02 \\ 
     1.0 & 0.4&0.9865112 &  0.9865114 &  0.0000002 & 0.9974 &  1.090e-02 \\ 
     1.0 & 0.6&0.9975042 &  0.9975042 &  0.0       & 0.9974 &  1.0e-04   \\ 
     1.0 & 0.8&0.9997222 &  0.9997222 &  0.0       & 0.9801 &  1.960e-02 \\ 
     1.0 & 1.0&0.9930872 &  0.9930876 &  0.0000004 & 0.9556 &  3.750e-02 \\ 
     \bottomrule
    \end{tabular}
    %\end{center}
    %\end{table}
\end{frame}
\end{document}
2
  • longtable in beamer doesn't preserve all features as it have in in the document classes as are article, book, etc. Consequently you need to manually insert column headers (if you like to have them) in each slide in frame.

  • In your MWE you use table environment, what can mean, that you actually interested that table is fit in one frame. This can be achieved, if you sufficiently reduce font size as was o @Mico in his answer.

  • In case, that you like to have bigger fonts in table, you can mimic longtable on the following way:

    • table split in two parts
    • each part use tabular table environment
    • into each part insert columns headers
\documentclass[mathserif]{beamer}
\usetheme{Berlin}
\setbeamertemplate{frametitle continuation}%
                  {(\insertcontinuationcount)%
                  }% end frame title continuation

\usepackage[T1]{fontenc}
\usepackage{times}
\usepackage[english]{babel}
\usepackage{siunitx}
    
    \begin{document}
\begin{frame}[allowframebreaks]
\frametitle{My longtable}
\sisetup{table-format=1.7,
         tight-spacing=true}
\setlength\tabcolsep{3pt}
\setlength\extrarowheight{1pt}
   \small
    \begin{tabular}{|*{2}{S[table-format=1.1]|}
                          S|S|S|
                          S[table-format=1.3]|
                          S[table-format=1.3e-1]|}
    \hline
{x} & {t}   &   {$U_{\mathrm{numeric}}(x,t)$}
                &   {$U_{\mathrm{exact}}(x,t)$}
                    &   {Error}
                        &   {Ref\textsubscript{solution}}
                            & {Ref\textsubscript{Error}}                \\ \hline\hline
0   & 0     & 0.7938824 & 1         & 0.2061176 & 1.0    & 0.0   e0     \\ \hline
0   & 0.2   & 1.006211  & 0.9955687 & 0.0106423 & 0.9902 & 5.400 e-03   \\ \hline
0   & 0.4   & 0.9876852 & 0.9824309 & 0.0052543 & 0.9627 & 1.980 e-02   \\ \hline
0   & 0.6   & 0.9503579 & 0.9610430 & 0.0106851 & 0.9235 & 3.750 e-02   \\ \hline
0   & 0.8   & 0.8949527 & 0.9321290 & 0.0371763 & 0.8827 & 4.950 e-02   \\ \hline
0   & 1.0   & 0.8224107 & 0.8966296 & 0.0742189 & 0.8542 & 4.250 e-02   \\ \hline
0.5 & 0     & 1.009713  & 0.9845362 & 0.0251768 & 0.9845 & 0.0   E0     \\ \hline
0.5 & 0.2   & 0.9953282 & 0.9966049 & 0.0012767 & 0.9994 & 2.800 e-03   \\ \hline
0.5 & 0.4   & 0.9988702 & 0.9999306 & 0.0010604 & 0.9946 & 5.300 e-03   \\ \hline
    \end{tabular}

%---------------------------------------------------------------%
     \begin{tabular}{|*{2}{S[table-format=1.1]|}
                          S|S|S|
                          S[table-format=1.3]|
                          S[table-format=1.3,
                            table-figures-exponent=2]|}
    \hline
{x} & {t}   &   {$U_{\mathrm{numeric}}(x,t)$}
                &   {$U_{\mathrm{exact}}(x,t)$}
                    &   {Error}
                        &   {Ref\textsubscript{solution}}
                            & {Ref\textsubscript{Error}}                \\ \hline\hline
0.5 & 0.6   & 0.9953922 & 0.9943961 & 0.0009961 & 0.9734 & 2.100 e-02   \\ \hline
0.5 & 0.8   & 0.9850632 & 0.9801960 & 0.0048672 & 0.9459 & 3.430 e-02   \\ \hline
0.5 & 1.0   & 0.9683171 & 0.9578230 & 0.0104941 & 0.9316 & 2.620 e-02   \\ \hline
1.0 &0      & 0.940015  & 0.9400148 & 0.0000002 & 0.9400 & 0.0   e0     \\ \hline
1.0 & 0.2   & 0.9671292 & 0.9671279 & 0.0000013 & 0.9775 & 1.040 e-02   \\ \hline
1.0 & 0.4   & 0.9865112 & 0.9865114 & 0.0000002 & 0.9974 & 1.090 e-02   \\ \hline
1.0 & 0.6   & 0.9975042 & 0.9975042 & 0.0       & 0.9974 & 1.0   e-4    \\ \hline
1.0 & 0.8   & 0.9997222 & 0.9997222 & 0.0       & 0.9801 & 1.960 e-02   \\ \hline
1.0 & 1.0   & 0.9930872 & 0.9930876 & 0.0000004 & 0.9556 & 3.750 e-02   \\ \hline
    \end{tabular}
\end{frame}
\end{document}

table

You must log in to answer this question.

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