5

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.

enter image description here

1 Answer 1

4

adjustbox comes with max totalsize for such cases.

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

\begin{frame}[t]
\frametitle<1>{AA}%
\frametitle<2>{BB}%
\adjustbox{max totalsize={0.85\paperwidth}{0.85\textheight}}{
    \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}

enter image description here

2
  • 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

You must log in to answer this question.

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