2

I have for a long time been using a code to place beamer buttons on a slide that is very inefficient as it requires me to specify exactly the position of each button. Below a MWE of the code I am using.

Is there anyway that I can avoid specifying the position of the button? I.e. they would just line up automatically from the bottom right hand corner to the left ...

\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}

enter image description here

1 Answer 1

4

Here is one way using chains. (I removed all packages that are not related to the problem but left babel to show that you also may want to use the TikZ library of the same name.)

\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}

enter image description here

Another way is to create a command that adds a button left of the previous button. (If you think you will add so many buttons that one row is not sufficient, please let me know.)

\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}
3
  • Wow. This is great specially the second solution. Thank you very much. The second row would be a cherry on top of the cake. Thank you.
    – phdstudent
    Mar 4, 2020 at 9:30
  • Wait, I am a bit confused, where do I actually put the links on the last piece of code?
    – phdstudent
    Mar 4, 2020 at 10:21
  • @phdstudent I was assuming the links are all of the form Link<number> so you add them with \AddButton{<label>}{<number>} If this is not the case, you can use \newcommand{\AddButton}[3][]{% \begin{tikzpicture}[remember picture, overlay] \ifFrameHasButton \node[left=1em of tmpbutton] (tmpbutton) {\hyperlink{#3}{\beamerbutton{#2~link}}}; \else \path ([yshift=1em]current page.south east) node[anchor=south east] (tmpbutton) {\hyperlink{#3}{\beamerbutton{#2~link}}}; \global\FrameHasButtontrue \fi \end{tikzpicture}}.
    – user194703
    Mar 4, 2020 at 14:55

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .