# Fit table in beamer

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{graphicx}
\begin{document}
\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?

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}

• I would like to know whether it is possible to highlight the first column and first row in a different color May 4, 2018 at 11:02
• @Natasha - The short answer to your follow-up queston is, "yes". However, not knowing which color, or colors, you have in mind, I can't give a specific longer answer. All I can suggest for now is that you familiarize yourself with the colortbl package and its \rowcolor and \columncolor macros.
– Mico
May 4, 2018 at 11:31
• Thanks for the tip with table and the resizebox. Feb 19, 2020 at 22:46
• @DavidBeauchemin - You're welcome. :-) Incidentally, while I did suggest using the \resizebox method for the table at hand, this method should not be regarded as a panacea or first-best solution. I recommended it for the table at hand purely because no other solution approach seemed feasible. In my experience, the \resizebox should not be employed once if the implied shrinkage exceeds about 20%.
– Mico
Feb 20, 2020 at 7:35
• @Mico I understasnd. Still a good workaround in last resort. Feb 20, 2020 at 21:14

I frequently do this by setting the font size of the contents of the table to tiny.

When You preview in PDF it looks as follows: