I inserted a table into a page of a presentation Beamer but the problem is that the array size exceeds the frame.
How to adjust the array size to the size of the frame?
[Tex/LaTex] adjust the array size to the size of the frame+Beamer
arraysbeamer
Related Solutions
Here the definition plus demonstration code of \Temporal
.
It works like \temporal
but uses boxes like the \Alt
suggested by me in Beamer alt command like visible instead of like only. In addition I added an optional argument which can be used to align the narrower alternatives to the left, middle or right ([l]
, [c]
or [r]
). This was necessary to support centered array cells.
\documentclass{beamer}
\usepackage{tikz}
\makeatletter
% Detect mode. mathpalette is used to detect the used math style
\renewcommand<>\Temporal[4][l]{%
\begingroup
\ifmmode
\expandafter\mathpalette
\expandafter\math@Temporal
\else
\expandafter\make@Temporal
\fi
{{#2}{#3}{#4}{#1}{#5}}%
\endgroup
}
% Un-brace the second argument (required because \mathpalette reads the three arguments as one
\newcommand\math@Temporal[2]{\math@@Temporal{#1}#2}
% Set the three arguments in boxes. The math style is given by #1. \m@th sets \mathsurround to 0.
\newcommand\math@@Temporal[4]{%
\setbox\z@ \hbox{$\m@th #1{#2}$}%
\setbox\@ne\hbox{$\m@th #1{#3}$}%
\setbox\tw@\hbox{$\m@th #1{#4}$}%
\@Temporal
}
% Un-brace the argument
\newcommand\make@Temporal[1]{\make@@Temporal#1}
% Set the two arguments into normal boxes
\newcommand\make@@Temporal[3]{%
\sbox\z@ {#1}%
\sbox\@ne{#2}%
\sbox\tw@{#3}%
\@Temporal
}
% Place one of the two boxes using \rlap and place a \phantom box with the maximum of the two boxes
\newcommand\@Temporal[2]{%
\setbox\@tempboxa\null
\ht\@tempboxa
\ifnum\ht\z@>\ht\@ne
\ifnum\ht\z@>\ht\tw@
\ht\z@
\else
\ht\tw@
\fi
\else
\ifnum\ht\@ne>\ht\tw@
\ht\@ne
\else
\ht\tw@
\fi
\fi
\dp\@tempboxa
\ifnum\dp\z@>\dp\@ne
\ifnum\dp\z@>\dp\tw@
\dp\z@
\else
\dp\tw@
\fi
\else
\ifnum\dp\@ne>\dp\tw@
\dp\@ne
\else
\dp\tw@
\fi
\fi
\wd\@tempboxa
\ifnum\wd\z@>\wd\@ne
\ifnum\wd\z@>\wd\tw@
\wd\z@
\else
\wd\tw@
\fi
\else
\ifnum\wd\@ne>\wd\tw@
\wd\@ne
\else
\wd\tw@
\fi
\fi
% The \hfil's center the content. Remove one or both of them to right or left align them:
\rlap{\hbox to \wd\@tempboxa{%
\ifx l#1\else\hfil\fi
\temporal#2%
{\box\z@}%
{\box\@ne}%
{\box\tw@}%
\ifx r#1\else\hfil\fi
}}%
\box\@tempboxa
}
\makeatother
\begin{document}
% Test the different modes and math styles
\begin{frame}<1-3>
Display:
\[
\begin{split}
\frac{dy}{dx} &= \left(\frac{2x}{x^2+1} + \frac{1}{2(x+3)} - \frac{1}{x-1}
\right)
\Temporal<2>{\frac{(x^2+1)\sqrt{x+3}}{x-1}}{y}{\int_x^y z}.
\end{split}
\]
In-Text:
\(
\frac{dy}{dx} = \left(\frac{2x}{x^2+1} + \frac{1}{2(x+3)} - \frac{1}{x-1}
\right)
\Temporal<2>{\frac{(x^2+1)\sqrt{x+3}}{x-1}}{y}{\int_x^y z}.
\)
Subscript:
\(
\frac{dy}{dx} = \left(\frac{2x}{x^2+1} + \frac{1}{2(x+3)} - \frac{1}{x-1}
\right) X_{\Temporal<2>{\frac{(x^2+1)\sqrt{x+3}}{x-1}}{y}{\int_x^y z}}.
\)
\[
\frac{dy}{dx} = \left(\frac{2x}{x^2+1} + \frac{1}{2(x+3)} - \frac{1}{x-1}
\right) X_{\Temporal<2>{\frac{(x^2+1)\sqrt{x+3}}{x-1}}{y}{\int_x^y z}}.
\]
Sub-Subscript:
\(
\frac{dy}{dx} = \left(\frac{2x}{x^2+1} + \frac{1}{2(x+3)} - \frac{1}{x-1}
\right) X_{X_{\Temporal<2>{\frac{(x^2+1)\sqrt{x+3}}{x-1}}{y}{\int_x^y z}}}.
\)
\[
\frac{dy}{dx} = \left(\frac{2x}{x^2+1} + \frac{1}{2(x+3)} - \frac{1}{x-1}
\right) X_{X_{\Temporal<2>{\frac{(x^2+1)\sqrt{x+3}}{x-1}}{y}{\int_x^y z}}}.
\]
Text-mode:
XXXX \Temporal<2>{aaaaa}{Ag}{AAAA}.
\end{frame}
\begin{frame}<1-3>
\[ \left(
\begin{array}{ccc}
\Temporal<2>[r]{\frac{(x^2+1)\sqrt{x+3}}{x-1}}{y}{\int_x^y z} &
\Temporal<2>[c]{\frac{(x^2+1)\sqrt{x+3}}{x-1}}{y}{\int_x^y z} &
\Temporal<2>[l]{\frac{(x^2+1)\sqrt{x+3}}{x-1}}{y}{\int_x^y z} \\
\Temporal<2>[l]{\frac{(x^2+1)\sqrt{x+3}}{x-1}}{y}{\int_x^y z} &
\Temporal<2>[c]{\frac{(x^2+1)\sqrt{x+3}}{x-1}}{y}{\int_x^y z} &
\Temporal<2>[r]{\frac{(x^2+1)\sqrt{x+3}}{x-1}}{y}{\int_x^y z} \\
\Temporal<2>[c]{<2}{=2}{>2} &
\Temporal<2>{\int x}{\iint x}{\oint x} \\
\end{array}
\right)
\]
\end{frame}
\end{document}
(the size differences in the images is due to different cropping)
If you really need numbering, you can do like
\documentclass{beamer}
\usepackage{mathtools}
\begin{document}
\begin{frame}
\frametitle{Big formula}
\begin{equation}
\label{eq:recursive}
\resizebox{.9\textwidth}{!}{$\displaystyle % restart math mode!
R_{k+1}(a,b) =
\begin{dcases}
1 & \text{if $a=b$} \\
0 & \text{if $I(a)=\phi$ or $I(b)=\phi$} \\
\frac{C}{|I(a)|\,|I(b)|}
\sum_{i=1}^{|I(a)|}
\sum_{j=1}^{|I(b)|} R_k(I_i(a),I_j(b)) & \text{otherwise}
\end{dcases}
$} % end math mode and close the box to be resized
\end{equation}
\end{frame}
\end{document}
Note that I used dcases
provided by mathtools
, which gains some horizontal space as the limits are typeset above and below the summation sign. Alternatively, you can type
\documentclass{beamer}
\begin{document}
\begin{frame}
\frametitle{Big formula}
\begin{equation}
\label{eq:recursive}
\resizebox{.9\textwidth}{!}{$\displaystyle % restart math mode
R_{k+1}(a,b) =
\begin{cases}
1 & \text{if $a=b$} \\
0 & \text{if $I(a)=\phi$ or $I(b)=\phi$} \\
\frac{C}{|I(a)|\,|I(b)|}
\sum\limits_{i=1}^{|I(a)|}
\sum\limits_{j=1}^{|I(b)|} R_k(I_i(a),I_j(b)) & \text{otherwise}
\end{cases}
$} % end math mode and close the box to be resized
\end{equation}
\end{frame}
\end{document}
This will use smaller summation signs.
Notes.
The
cases
(ordcases
) environment is more convenient than usingarray
.For the conditions, it's better to use
\text
and switch to math mode inside it, rather than using clumsy\mbox
commands with spaces.
Best Answer
You can resize a
tabular
to fit exactly inside the text block of the frame using the functionality provided bygraphicx
- loaded by default by thebeamer
class. More specifically, you can use\resizebox{<width>}{<height>}{<stuff>}
to resize<stuff>
to width<width>
and height<height>
. If you wish to maintain the aspect ratio of<stuff>
, replace one of the lengths with!
:Of course, this also shrinks the font size (actually everything, including the rule widths). If this is not ideal, you can use some methods provided in Column padding in tables (to remove some space) or perhaps reduce the number of columns altogether. Perhaps even displaying them on separate frames using column selection. For this see Easiest way to delete a column?
Although the above discussion references
tabular
, it applies equally toarray
as well. The syntax would resemble