5

I have a presentation in beamer with several slides showing a graph with a coordinate system. I want the graph to be (more or less) centered on the slide, with the origin of the coordinate system in the same place. The issue is that I have different labels to the left of the coordinate system, so simple centering doesn't work.

Minimal working example:

\documentclass[11pt,usenames,dvipsnames]{beamer}
\usetheme{Boadilla}             
\usepackage{etex}               
\usepackage{color}
\usepackage{amsmath,amssymb}
\usepackage{graphicx}
\usepackage{lmodern}            
\usepackage{tikz}              

\beamertemplatenavigationsymbolsempty %gets rid of navigation at bottom of each slide

\begin{document}
\frame{
    \frametitle{no tax}
    \begin{center}
    \begin{tikzpicture}[scale=1.3]
    \draw[->, thick] (-0.2,0) -- (4.2,0) node[right] {$x$}; %x-axis
    \draw[->, thick] (0,-0.2) -- (0,4.2) node[above] {$y$}; %y-axis
    \draw[thick]  (0,3.5) node[left=-1pt] {$\frac{I}{p_y}$} -- (3.5,0) node[below=-1pt] {$\frac{I}{p_x}$}; %BC
    \node (v3) at (1.65,1.85) {} ;
    \fill (1.65,1.85)  circle[radius=1.5pt] node[above right=-1pt] {A}; 
    \draw[thick]  plot[smooth, tension=.7] coordinates {(0.85,4) (1,3) (v3) (3,1.15) (4,0.9) }; %indifference curve
    \end{tikzpicture}
    \end{center}
    }

    \frame{
    \frametitle{Tax on $y$}
    \begin{center}
    \begin{tikzpicture}[scale=1.3]
    \draw[->, thick] (-0.2,0) -- (4.2,0) node[right] {$x$}; %x-axis
    \draw[->, thick] (0,-0.2) -- (0,4.2) node[above] {$y$}; %y-axis
    \draw[thick]  (0,3.5) node[left=-1pt] {$\frac{I}{p_y}$} -- (3.5,0) node[below=-1pt] {$\frac{I}{p_x}$}; %BC
    \node (v3) at (1.65,1.85) {} ;
    \fill (1.65,1.85)  circle[radius=1.5pt] node[above right=-1pt] {A}; 
    \draw[thick]  plot[smooth, tension=.7] coordinates {(0.85,4) (1,3) (v3) (3,1.15) (4,0.9) };
    \draw[thick]   (0,2) node[left=-1pt] {$\frac{I}{(1+t_y)p_y}$} -- (3.5,0) node[below=-1pt] {$\frac{I}{p_x}$}; %BC
    \fill (2,0.85)  circle[radius=1.5pt] node[below left =-1pt] {B}; 
    \draw[thick]   plot[smooth, tension=.7] coordinates {(0.5,2.75) (1,1.75) (1.95,0.9) (2.95,0.5) (3.85,0.4) };
    \end{tikzpicture}
    \end{center}
    }
\end{document}

Thanks for your help!

Dominika
  • 127
  • Does it helps? http://tex.stackexchange.com/a/244103/1952 – Ignasi May 06 '16 at 07:22
  • This one can also be applied to beamer: http://tex.stackexchange.com/a/308072/1952 – Ignasi May 06 '16 at 07:23
  • @Ignasi Adding [scale=1.3, remember picture, overlay, shift={(current page.center)}] behind \begin{tikzpicture} indeed leads to the picture always being in the same place, thanks! Unfortunately, it also moves it to the upper right corner of the slide. How do I get it to the center? – Dominika May 06 '16 at 07:49
  • Which point of your graphic do you want in frame center? – Ignasi May 06 '16 at 08:10
  • I would like to have (approximately) the center of my graphic in the center of the slide. So the lower left corner of the graphic should be approximately a third from the bottom and a third to the right. I've tried to give an exact place (as in shift={(current page.(5,5))}) but that doesn't work. – Dominika May 06 '16 at 08:32

2 Answers2

4

The solution in this case is easier than using absolute positioning on beamer. As both graphics are similar in size, except for the left label, you can include this long label in first graphic as a \phantom text. This way is not printed but the corresponding space is preserved, both graphics have same width and both will be centered on same slide position.

\documentclass[11pt,usenames,dvipsnames]{beamer}
\usetheme{Boadilla}             
\usepackage{etex}               
\usepackage{color}
\usepackage{amsmath,amssymb}
\usepackage{graphicx}
\usepackage{lmodern}            
\usepackage{tikz}              

\beamertemplatenavigationsymbolsempty %gets rid of navigation at bottom of each slide

\begin{document}
\frame{
    \frametitle{no tax}
    \begin{center}
    \begin{tikzpicture}[scale=1.3]
    \draw[->, thick] (-0.2,0) -- (4.2,0) node[right] {$x$}; %x-axis
    \draw[->, thick] (0,-0.2) -- (0,4.2) node[above] {$y$}; %y-axis

    %%%%%%%%%% This is new %%%%%%%%%%%%%%%%%%%%%%%%%%
    \draw[thick] (0,2) node[left=-1pt] {\phantom{$\frac{I}{(1+t_y)p_y}$}}; %BC

    \draw[thick]  (0,3.5) node[left=-1pt] {$\frac{I}{p_y}$} -- (3.5,0) node[below=-1pt] {$\frac{I}{p_x}$}; %BC
    \node (v3) at (1.65,1.85) {} ;
    \fill (1.65,1.85)  circle[radius=1.5pt] node[above right=-1pt] {A}; 
    \draw[thick]  plot[smooth, tension=.7] coordinates {(0.85,4) (1,3) (v3) (3,1.15) (4,0.9) }; %indifference curve
    \end{tikzpicture}
    \end{center}
    }

    \frame{
    \frametitle{Tax on $y$}
    \begin{center}
    \begin{tikzpicture}[scale=1.3]
    \draw[->, thick] (-0.2,0) -- (4.2,0) node[right] {$x$}; %x-axis
    \draw[->, thick] (0,-0.2) -- (0,4.2) node[above] {$y$}; %y-axis
    \draw[thick]  (0,3.5) node[left=-1pt] {$\frac{I}{p_y}$} -- (3.5,0) node[below=-1pt] {$\frac{I}{p_x}$}; %BC
    \node (v3) at (1.65,1.85) {} ;
    \fill (1.65,1.85)  circle[radius=1.5pt] node[above right=-1pt] {A}; 
    \draw[thick]  plot[smooth, tension=.7] coordinates {(0.85,4) (1,3) (v3) (3,1.15) (4,0.9) };
    \draw[thick]   (0,2) node[left=-1pt] {$\frac{I}{(1+t_y)p_y}$} -- (3.5,0) node[below=-1pt] {$\frac{I}{p_x}$}; %BC
    \fill (2,0.85)  circle[radius=1.5pt] node[below left =-1pt] {B}; 
    \draw[thick]   plot[smooth, tension=.7] coordinates {(0.5,2.75) (1,1.75) (1.95,0.9) (2.95,0.5) (3.85,0.4) };
    \end{tikzpicture}
    \end{center}
    }
\end{document}

enter image description here

Ignasi
  • 136,588
  • Thank you, this works nicely in this case! I gather that there is no easy way to specifcy an absolute position? (I have some more complicated graphs where elements both to the right and the left of the graph change, and there it might be easier to specify the absolute position.) – Dominika May 06 '16 at 10:38
1

This method works here since both graphs have the same right-side limit. Graphs with the same left-side limit could be dealt with by eliminating the \llap. However, this approach will not intrinsically work if one graph has extra stuff off to both the left and right.

It works with the atbegshi package to overlay something over the graph at a specified (x,y) coordinate on the page, using the given \atxy{<x>}{<y>}{<content>} macro.

\documentclass[11pt,usenames,dvipsnames]{beamer}
\usetheme{Boadilla}             
\usepackage{etex}               
\usepackage{color}
\usepackage{amsmath,amssymb}
\usepackage{graphicx}
\usepackage{lmodern}            
\usepackage{tikz}              

\beamertemplatenavigationsymbolsempty %gets rid of navigation at bottom of each 

\usepackage{atbegshi}
\def\PageTopMargin{1in}
\def\PageLeftMargin{1in}
\newcommand\atxy[3]{%
 \AtBeginShipoutNext{\AtBeginShipoutAddToBoxForeground{%
  \smash{\hspace*{\dimexpr-\PageLeftMargin-\hoffset+#1\relax}%
  \raisebox{\dimexpr\PageTopMargin+\voffset-#2\relax}{#3}}}}}
\def\earmark{%
  \atxy{0pt}{\paperheight}{\begin{tikzpicture}
  \node[outer sep=0.46in] (earmark) {};
  \draw[blue!40, fill, opacity=0.25] (earmark.south west) -- (earmark.south east) -- 
    (earmark.north west)-- (earmark.south west);
  \end{tikzpicture}}
}

\begin{document}
\frame{
    \frametitle{no tax}
\atxy{4in}{3.3in}{\llap{%
    \begin{tikzpicture}[scale=1.3]
    \draw[->, thick] (-0.2,0) -- (4.2,0) node[right] {$x$}; %x-axis
    \draw[->, thick] (0,-0.2) -- (0,4.2) node[above] {$y$}; %y-axis
    \draw[thick]  (0,3.5) node[left=-1pt] {$\frac{I}{p_y}$} -- (3.5,0) node[below=-1pt] {$\frac{I}{p_x}$}; %BC
    \node (v3) at (1.65,1.85) {} ;
    \fill (1.65,1.85)  circle[radius=1.5pt] node[above right=-1pt] {A}; 
    \draw[thick]  plot[smooth, tension=.7] coordinates {(0.85,4) (1,3) (v3) (3,1.15) (4,0.9) }; %indifference curve
    \end{tikzpicture}%
}}
    }

    \frame{
    \frametitle{Tax on $y$}
\atxy{4in}{3.3in}{\llap{%
    \begin{tikzpicture}[scale=1.3]
    \draw[->, thick] (-0.2,0) -- (4.2,0) node[right] {$x$}; %x-axis
    \draw[->, thick] (0,-0.2) -- (0,4.2) node[above] {$y$}; %y-axis
    \draw[thick]  (0,3.5) node[left=-1pt] {$\frac{I}{p_y}$} -- (3.5,0) node[below=-1pt] {$\frac{I}{p_x}$}; %BC
    \node (v3) at (1.65,1.85) {} ;
    \fill (1.65,1.85)  circle[radius=1.5pt] node[above right=-1pt] {A}; 
    \draw[thick]  plot[smooth, tension=.7] coordinates {(0.85,4) (1,3) (v3) (3,1.15) (4,0.9) };
    \draw[thick]   (0,2) node[left=-1pt] {$\frac{I}{(1+t_y)p_y}$} -- (3.5,0) node[below=-1pt] {$\frac{I}{p_x}$}; %BC
    \fill (2,0.85)  circle[radius=1.5pt] node[below left =-1pt] {B}; 
    \draw[thick]   plot[smooth, tension=.7] coordinates {(0.5,2.75) (1,1.75) (1.95,0.9) (2.95,0.5) (3.85,0.4) };
    \end{tikzpicture}%
}}
    }
\end{document}

enter image description here