[Tex/LaTex] Fit table in beamer

beamertables

I am using the rescale option that was suggested in the other posts in this forum to fit a table in beamer. However, the contents of the table move out of the frame.

\documentclass{beamer}
\usepackage{adjustbox,lipsum}
\usepackage{graphicx}
\begin{document}
%%\begin{adjustbox}{max width=\textwidth}
\scalebox{0.7}{
\begin{table}[h!]
\centering
\caption{ }
\begin{tabular}{|c|c|c|c|c|c| } 
\hline
Name & Name&Name&NameName&NameName\\ 
\hline
NameName&-&-&-&-\\
NameName&NameName B &NameName B &- &NameName B\\
NameName&NameName A&NameName A&NameName A&NameName A\\
NameName&NameName B &NameName &-&- \\
NameName&NameName C&NameName C&NameName C&-\\
NameName&-&NameName&-&-\\
NameName&-&NameName&-&\\
\hline
\end{tabular}
\end{table}
}
\end{document}

Could someone help me to identify what's wrong in syntax that I am using?

enter image description here

Best Answer

Some suggestions:

  • Don't forget to employ frame environments in a beamer document.

  • In a beamer document, table and figure environments do not "float", in the LaTeX-specific sense. Hence, the main reason for using table and figure environments -- to act as "wrappers" around the core material -- is gone. The general recommendation: don't use table and figure environments in beamer documents.

  • For your document, get rid of the begin{table} and \end{table} directives and place the argument of \caption in the frame title.

  • There's not much to say about the specific tabular environment at hand. (Obviously, the many instances of NameName will get replaced with something more relevant...) The usual tricks and tips for making tabular material fit inside the text block therefore do not appear to provide much traction. I suggest that you use, for the specific table at hand, a \resizebox directive to make it fit inside the width of the text block.

  • No need to load the graphicx package explicitly: In the beamer document class, this package is loaded automatically.

Here, then, is how I would rewrite your code:

\documentclass{beamer}
\begin{document}
\begin{frame}{Tissue-specific expression of isoenzymes of 
  NameNamelase for seven different species}
\resizebox{\textwidth}{!}{%
  \begin{tabular}{|c|c|c|c|c|c|}
  \hline
  Name & Name&Name&NameName&NameName\\
  \hline
  NameName&-&-&-&-\\
  NameName&NameName B &NameName B &- &NameName B\\
  NameName&NameName A&NameName A&NameName A&NameName A\\
  NameName&NameName B &NameName &-&- \\
  NameName&NameName C&NameName C&NameName C&-\\
  NameName&-&NameName&-&-\\
  NameName&-&NameName&-&\\
  \hline
  \end{tabular}
} % end of scope of "\resizebox"  directive
\end{frame}
\end{document}