# How to make tikzpicture full screen in beamer whlie keeping aspect ratio

I have a tikzpicture which has an unpredictable aspect ratio (actually, due to clipping, the aspect ratio varies across overlays). I want to have the tikzpicture always scaled up in beamer to the maximum possible size, but without changing the aspect ratio.

Here is a nMWE:

\documentclass{beamer}
\usepackage{tikz}
\begin{document}
\usetikzlibrary{decorations.text, positioning}

\begin{frame}{\only<1>{AA}
\only<2>{BB}
}
\resizebox{.85\paperwidth}{!}{
\begin{tikzpicture}
\clip<1> (0.0, 0.0) rectangle (10.0, 2);
\clip<2> (2, 2) rectangle (6, 12);

\draw [help lines] (0,0) grid (25,13);
\end{tikzpicture}
}
\end{frame}
\end{document}


In the output below, neither picture should be cut off. That is, I want something other than the \resizebox approach which will deal with tall pictures as well as with wide ones.

adjustbox comes with max totalsize for such cases.

\documentclass{beamer}
\usepackage{tikz}
\usetikzlibrary{decorations.text, positioning,calc}
\begin{document}

\begin{frame}[t]
\frametitle<1>{AA}%
\frametitle<2>{BB}%
\begin{tikzpicture}
\clip<1> (0.0, 0.0) rectangle (10.0, 2);
\clip<2> (2, 2) rectangle (6, 12);

\draw [help lines] (0,0) grid (25,13);
\end{tikzpicture}
}
\end{frame}
\end{document}


• Thank you!! Is the \restheight needed for something?
– CPBL
May 23, 2019 at 8:58
• @CPBL No. Good catch! I removed it.
– user121799
May 23, 2019 at 12:07