Created
June 4, 2020 08:29
-
-
Save Rmano/c68789c5efe8feca897da66d4e991be8 to your computer and use it in GitHub Desktop.
Find biggest bounding box in a tikzpicture in beamer and then fix it.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
\documentclass{beamer} | |
\usepackage[utf8]{inputenc} | |
\usepackage{tikz} | |
\usetikzlibrary{arrows,overlay-beamer-styles,calc} | |
\makeatletter | |
% Thanks to Paul Gaborit https://tex.stackexchange.com/a/179946/38080 | |
\def\extractcoord#1#2#3{ | |
\path let \p1=(#3) in \pgfextra{ | |
\pgfmathsetmacro#1{\x{1}/\pgf@xx} | |
\pgfmathsetmacro#2{\y{1}/\pgf@yy} | |
\xdef#1{#1} \xdef#2{#2} | |
}; | |
} | |
\makeatother | |
\newcommand{\showboundingbox}{% | |
% | |
% Show the bounding box of the tikzpicture. Use as last command. | |
% It will not change the bounding box thanks to the overlay option. | |
% | |
\extractcoord\xa\ya{current bounding box.south west} | |
\extractcoord\xb\yb{current bounding box.north east} | |
\node [overlay, draw=red, fill=white, opacity=0.8, font=\tiny\ttfamily, anchor=north east] at (current bounding box.north east) {(\xa, \ya) (\xb, \yb)}; | |
} | |
\begin{document} | |
% mode 1; it will jump. | |
\begin{frame} | |
\frametitle{jumping} | |
\begin{center} | |
\begin{tikzpicture}[>=stealth',thick] | |
\node at (0,0) (1) {$1$}; | |
\node at (2,0) (2) {$2$}; | |
\draw<2-> (1) edge[bend left,->] (2); | |
\draw<3-> (2) edge[bend left,->] (1); | |
% print how much is big this picture (it will change every overlay) | |
\showboundingbox | |
\end{tikzpicture} | |
\end{center} | |
\end{frame} | |
%%% note down the biggest coordinates and add a | |
%%% path to use as bounding box (I normally use a bit bigger | |
%%% one that what I found | |
\begin{frame} | |
\frametitle{jumping} | |
\begin{center} | |
\begin{tikzpicture}[>=stealth',thick] | |
\path [use as bounding box] (-0.25,-0.45) rectangle (2.25,0.45); | |
\node at (0,0) (1) {$1$}; | |
\node at (2,0) (2) {$2$}; | |
\draw<2-> (1) edge[bend left,->] (2); | |
\draw<3-> (2) edge[bend left,->] (1); | |
% \showboundingbox %not needed anymore | |
\end{tikzpicture} | |
\end{center} | |
\end{frame} | |
\end{document} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment