我在 Beamer 中有一个演示文稿,其中有几张幻灯片显示了一个带有坐标系的图表。我希望图表(或多或少)位于幻灯片的中心,坐标系的原点位于同一位置。问题是我在坐标系左侧有不同的标签,因此简单的居中不起作用。
最小工作示例:
\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}
感谢您的帮助!
答案1
在这种情况下,解决方案比使用绝对定位更简单beamer
。由于两个图形大小相似,除了左侧标签外,您可以将这个长标签作为文本包含在第一个图形中\phantom
。这种方式不会打印,但会保留相应的空间,两个图形具有相同的宽度,并且都将在相同的幻灯片位置居中。
\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}
答案2
此方法在此有效,因为两个图具有相同的右侧极限。具有相同左侧极限的图可以通过消除来处理\llap
。但是,如果一个图的左侧和右侧都有多余的东西,则此方法本质上不起作用。
它与atbegshi
包一起工作,使用给定的宏在页面上指定的 (x,y) 坐标处的图形上叠加某些内容\atxy{<x>}{<y>}{<content>}
。
\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}