正如标题所说,我无法将 tikz 图片保持在同一位置。
这里有一个 MWE,您可以亲自看看。
\documentclass[xcolor=x11names,compress]{beamer}
\usepackage{graphicx}
\usepackage{tikz}
\setbeamercolor{block title}{use=structure,fg=white,bg=DeepSkyBlue4}
\setbeamercolor{block body}{use=structure,fg=black,bg=DeepSkyBlue4!10!white}
\begin{document}
\subsection*{Test 1}
\begin{frame}{Frame 1}
\begin{columns}[onlytextwidth]
\begin{column}{.4\textwidth}
Test: A really long line of text for a presentation\\
\end{column}
\begin{column}{.6\textwidth}
\centering
\begin{tikzpicture}
\draw[->,very thick,cap=rect] (3.8,1.2)--(4.8,1.2);
\node at (4.85,0.95) {$x$};
\draw[->,very thick, cap=rect] (3.8,1.2)--(3.8,2.2);
\node at (4.05, 2.1) {$y$};
\draw[very thick] (3.8,1.2) circle (0.1);
\draw[very thick] (3.8,1.2) circle (0.02);
\node at (3.65, 0.95) {$z$};
\draw[opacity=0.15] (1.5,-2.59861) circle (0.7cm);
\shade[ball color=Gold3,opacity=0.105] (1.5,-2.59861) circle (0.7cm);
\draw[opacity=0.15] (0.0,0) circle (0.7cm);
\shade[ball color=DodgerBlue3,opacity=0.105] (0.0,0) circle (0.7cm);
\end{tikzpicture}
\end{column}
\end{columns}
\end{frame}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\subsection*{Test 2}
\begin{frame}{Frame 2}
\begin{columns}[onlytextwidth]
\begin{column}{.4\textwidth}
\begin{block}{Test}
Make a test with some more text
\end{block}
\end{column}
\begin{column}{.6\textwidth}
\centering
\begin{tikzpicture}
\draw[->,very thick,cap=rect] (3.8,1.2)--(4.8,1.2);
\node at (4.85,0.95) {$x$};
\draw[->,very thick, cap=rect] (3.8,1.2)--(3.8,2.2);
\node at (4.05, 2.1) {$y$};
\draw[very thick] (3.8,1.2) circle (0.1);
\draw[very thick] (3.8,1.2) circle (0.02);
\node at (3.65, 0.95) {$z$};
\draw[opacity=0.15] (1.5,-2.59861) circle (0.7cm);
\shade[ball color=Gold3,opacity=0.105] (1.5,-2.59861) circle (0.7cm);
\draw[opacity=0.15] (0.0,0) circle (0.7cm);
\shade[ball color=DodgerBlue3,opacity=0.105] (0.0,0) circle (0.7cm);
\end{tikzpicture}
\end{column}
\end{columns}
\end{frame}
\end{document}
我需要一个可以保留两个框架的解决方案,因此\only
等不是一个选项。
答案1
block
有一些内部分离,不知何故不会在宽度内受到限制。使用
\end{column}
\hfill
\begin{column}{.55\textwidth}
反而。
\documentclass[xcolor=x11names,compress]{beamer}
\usepackage{graphicx}
\usepackage{tikz}
\setbeamercolor{block title}{use=structure,fg=white,bg=DeepSkyBlue4}
\setbeamercolor{block body}{use=structure,fg=black,bg=DeepSkyBlue4!10!white}
\begin{document}
\subsection*{Test 1}
\begin{frame}{Frame 1}
\begin{columns}[onlytextwidth]
\begin{column}{.4\textwidth}
Test: A really long line of text for a presentation\\
\end{column}\hfill
\begin{column}{.55\textwidth}
\centering
\begin{tikzpicture}
\draw[->,very thick,cap=rect] (3.8,1.2)--(4.8,1.2);
\node at (4.85,0.95) {$x$};
\draw[->,very thick, cap=rect] (3.8,1.2)--(3.8,2.2);
\node at (4.05, 2.1) {$y$};
\draw[very thick] (3.8,1.2) circle (0.1);
\draw[very thick] (3.8,1.2) circle (0.02);
\node at (3.65, 0.95) {$z$};
\draw[opacity=0.15] (1.5,-2.59861) circle (0.7cm);
\shade[ball color=Gold3,opacity=0.105] (1.5,-2.59861) circle (0.7cm);
\draw[opacity=0.15] (0.0,0) circle (0.7cm);
\shade[ball color=DodgerBlue3,opacity=0.105] (0.0,0) circle (0.7cm);
\end{tikzpicture}
\end{column}
\end{columns}
\end{frame}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\subsection*{Test 2}
\begin{frame}{Frame 2}
\begin{columns}[onlytextwidth]
\begin{column}{.4\textwidth}
\begin{block}{Test}
Make a test with some more text
\end{block}
\end{column}\hfill
\begin{column}{.55\textwidth}
\centering
\begin{tikzpicture}
\draw[->,very thick,cap=rect] (3.8,1.2)--(4.8,1.2);
\node at (4.85,0.95) {$x$};
\draw[->,very thick, cap=rect] (3.8,1.2)--(3.8,2.2);
\node at (4.05, 2.1) {$y$};
\draw[very thick] (3.8,1.2) circle (0.1);
\draw[very thick] (3.8,1.2) circle (0.02);
\node at (3.65, 0.95) {$z$};
\draw[opacity=0.15] (1.5,-2.59861) circle (0.7cm);
\shade[ball color=Gold3,opacity=0.105] (1.5,-2.59861) circle (0.7cm);
\draw[opacity=0.15] (0.0,0) circle (0.7cm);
\shade[ball color=DodgerBlue3,opacity=0.105] (0.0,0) circle (0.7cm);
\end{tikzpicture}
\end{column}
\end{columns}
\end{frame}
\end{document}
答案2
受到@cfr 解决方案的启发——https://tex.stackexchange.com/a/217885/34618,对block
模板进行一些修改似乎可以解决问题。
代码
\documentclass[xcolor=x11names,compress]
{beamer}
\usepackage{graphicx}
\usepackage{tikz}
%
\setbeamertemplate{block begin}{
\vskip\baselineskip
\begin{beamercolorbox}[wd=\textwidth, ht=0.5cm, dp=0.2cm, leftskip=0.2cm]{block title}%
\usebeamerfont*{block title}%
{\rule[-0.4ex]{0mm}{2ex}\insertblocktitle}%
\end{beamercolorbox}%
{\nointerlineskip\vskip-0.5pt}%
\usebeamerfont{block body}%
\begin{beamercolorbox}[wd=\textwidth, leftskip=0.2cm,dp=0.2cm]{block body}%
\vskip-.75ex\vspace*{0.2cm}%
}
\setbeamertemplate{block end}{
\end{beamercolorbox}
\vspace*{.25cm}
}
\setbeamercolor{block title}{use=structure,fg=white,bg=DeepSkyBlue4}
\setbeamercolor{block body}{use=structure,fg=black,bg=DeepSkyBlue4!10!white}
\begin{document}
\subsection*{Test 1}
\begin{frame}{Frame 1}
\begin{columns}[onlytextwidth]
\begin{column}{.4\textwidth}
Test: A really long line of text for a presentation\\
\end{column}
\begin{column}{.6\textwidth}
\centering
\begin{tikzpicture}
\draw[->,very thick,cap=rect] (3.8,1.2)--(4.8,1.2);
\node at (4.85,0.95) {$x$};
\draw[->,very thick, cap=rect] (3.8,1.2)--(3.8,2.2);
\node at (4.05, 2.1) {$y$};
\draw[very thick] (3.8,1.2) circle (0.1);
\draw[very thick] (3.8,1.2) circle (0.02);
\node at (3.65, 0.95) {$z$};
\draw[opacity=0.15] (1.5,-2.59861) circle (0.7cm);
\shade[ball color=Gold3,opacity=0.105] (1.5,-2.59861) circle (0.7cm);
\draw[opacity=0.15] (0.0,0) circle (0.7cm);
\shade[ball color=DodgerBlue3,opacity=0.105] (0.0,0) circle (0.7cm);
\end{tikzpicture}
\end{column}
\end{columns}
\end{frame}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\subsection*{Test 2}
\begin{frame}{Frame 2}
\begin{columns}[onlytextwidth]
\begin{column}{.4\textwidth}
\begin{block}{Test}
Make a test with some more text
\end{block}
\end{column}
\begin{column}{.6\textwidth}
\centering
\begin{tikzpicture}
\draw[->,very thick,cap=rect] (3.8,1.2)--(4.8,1.2);
\node at (4.85,0.95) {$x$};
\draw[->,very thick, cap=rect] (3.8,1.2)--(3.8,2.2);
\node at (4.05, 2.1) {$y$};
\draw[very thick] (3.8,1.2) circle (0.1);
\draw[very thick] (3.8,1.2) circle (0.02);
\node at (3.65, 0.95) {$z$};
\draw[opacity=0.15] (1.5,-2.59861) circle (0.7cm);
\shade[ball color=Gold3,opacity=0.105] (1.5,-2.59861) circle (0.7cm);
\draw[opacity=0.15] (0.0,0) circle (0.7cm);
\shade[ball color=DodgerBlue3,opacity=0.105] (0.0,0) circle (0.7cm);
\end{tikzpicture}
\end{column}
\end{columns}
\end{frame}
\end{document}