长期以来,我一直使用代码将投影仪按钮放置在幻灯片上,但这种代码效率很低,因为它要求我精确指定每个按钮的位置。下面是我正在使用的代码的 MWE。
有什么办法可以避免指定按钮的位置吗?也就是说,它们会自动从右下角向左排列...
\documentclass[10pt]{beamer}%
\usepackage{appendixnumberbeamer}
\usepackage{caption}
\usepackage{subcaption}
\usepackage{booktabs}
\usepackage{bbm}
\usepackage{amsmath}
\usepackage{arydshln}
\usepackage{graphicx}
\usepackage{ mathrsfs }
\usepackage{multirow}
\usepackage{textpos}
\definecolor{darkblue}{RGB}{140,140,172}
\definecolor{bluegreen}{RGB}{173,173,224}
\definecolor{lightbluegreen}{RGB}{204,0,51}
\definecolor{cyan}{RGB}{30,24,83}
\usepackage[beamer,customcolors]{hf-tikz}
\usepackage{tikz}
\tikzset{hl/.style={
set fill color=black!00,
set border color=red!80!black,
},
}
\usetikzlibrary{patterns,arrows,decorations.pathreplacing}
\usetikzlibrary{shapes.callouts}
\usepackage[english]{babel}
\begin{document}
\begin{frame}{Button Positions}
\begin{tikzpicture}[remember picture, overlay]
\node[shift={(-0.9cm,0.5cm)}]() at (current page.south east){%
\hyperlink{Link6}{\beamerbutton{First link}}};
\end{tikzpicture}
\begin{tikzpicture}[remember picture, overlay]
\node[shift={(-2.7cm,0.5cm)}]() at (current page.south east){%
\hyperlink{Link5}{\beamerbutton{Second link}}};
\end{tikzpicture}
\begin{tikzpicture}[remember picture, overlay]
\node[shift={(-4.8cm,0.5cm)}]() at (current page.south east){%
\hyperlink{Link4}{\beamerbutton{Third link longer name}}};
\end{tikzpicture}
\begin{tikzpicture}[remember picture, overlay]
\node[shift={(-6.4cm,0.5cm)}]() at (current page.south east){%
\hyperlink{Link3}{\beamerbutton{Fourth link}}};
\end{tikzpicture}
\begin{tikzpicture}[remember picture, overlay]
\node[shift={(-7.5cm,0.5cm)}]() at (current page.south east){%
\hyperlink{Link2}{\beamerbutton{Fifth link}}};
\end{tikzpicture}
\begin{tikzpicture}[remember picture, overlay]
\node[shift={(-9.00cm,0.5cm)}]() at (current page.south east){%
\hyperlink{Link1}{\beamerbutton{Sixth link}}};
\end{tikzpicture}
\begin{tikzpicture}[remember picture, overlay]
\node[shift={(-1.35cm,0.95cm)}]() at (current page.south east){%
\hyperlink{Link7}{\beamerbutton{Seventh Link}}};
\end{tikzpicture}
\end{frame}
\end{document}
答案1
以下是使用 的一种方法chains
。(我删除了所有与问题无关的包,但留下来babel
以表明您可能还想使用 Ti钾同名的 Z 库。)
\documentclass[10pt]{beamer}%
\usepackage{appendixnumberbeamer}
\usepackage{tikz}
\usetikzlibrary{chains}
\usepackage[english]{babel}
\usetikzlibrary{babel}
\begin{document}
\begin{frame}{Button Positions}
\begin{tikzpicture}[remember picture, overlay,start chain=going left,node
distance=1ex]
\foreach \X/\Y [count=\Z] in {First/6,Second/5,Third/4,Fourth/3,%
Fifth/2,Sixth/1,Seventh/7}
{\ifnum\Z=1
\path ([yshift=1em]current page.south east) node[on chain,anchor=south east]
{\hyperlink{Link\Y}{\beamerbutton{\X~link}}};
\else
\path node[on chain]
{\hyperlink{Link\Y}{\beamerbutton{\X~link}}};
\fi}
\end{tikzpicture}%
\end{frame}
\end{document}
另一种方法是创建一个命令,在前一个按钮的左侧添加一个按钮。(如果您认为要添加的按钮太多,一行不够用,请告诉我。)
\documentclass[10pt]{beamer}%
\usepackage{appendixnumberbeamer}
\usepackage{tikz}
\usetikzlibrary{positioning}
\usepackage[english]{babel}
\usetikzlibrary{babel}
\usepackage{etoolbox}
% from https://tex.stackexchange.com/a/345082/194703
\BeforeBeginEnvironment{frame}{\FrameHasButtonfalse}
\newif\ifFrameHasButton
\newcommand{\AddButton}[3][]{%
\begin{tikzpicture}[remember picture, overlay]
\ifFrameHasButton
\node[left=1em of tmpbutton] (tmpbutton)
{\hyperlink{Link#3}{\beamerbutton{#2~link}}};
\else
\path ([yshift=1em]current page.south east)
node[anchor=south east] (tmpbutton)
{\hyperlink{Link#3}{\beamerbutton{#2~link}}};
\global\FrameHasButtontrue
\fi
\end{tikzpicture}}
\begin{document}
\begin{frame}[t]
\frametitle{Button Positions}
\AddButton{First}{6}%
\AddButton{Second}{5}%
\AddButton{Third}{4}%
\AddButton{Fourth}{3}%
\AddButton{Fifth}{2}%
\AddButton{Sixth}{1}%
\AddButton{Seventh}{7}%
\end{frame}
\begin{frame}[t]
\frametitle{Button Positions}
\AddButton{First}{6}%
\AddButton{Third}{4}%
\AddButton{Fifth}{2}%
\AddButton{Seventh}{7}%
\end{frame}
\end{document}