3

I am trying to introduce a few macros to make my life with columns in beamer a bit easier. The macros should take key-value pairs for customizing width, heights, alignment etc. I ran into problems using pgfkeys that don't get properly updated/initialized.

Below is a minimum example that I reduced to using only the column width as parameter. Here is what works and what doesn't:

  1. it works when I use two minipages and specify the column width (e.g., \leftcolumn[width=0.5]);
  2. when using minipages the default parameter of \leftcolumn in the frame does not work (try removing the [width=0.5]);
  3. using a columns environment (try uncommenting the block % --- Macros using columns... works only for the first column but not for the second.

Any help or suggestions would be highly appreciated!

\documentclass[11pt]{beamer}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{etoolbox}   
\makeatletter

% Make sure the macros exist. They will hold the relative width.
\newcommand*\leftwidth{}
\newcommand*\rightwidth{}

\pgfkeys{
    /slide/.cd ,
    leftcolumn/width/.code = \def\leftwidth{#1} ,
    leftcolumn/width/.default = 0.6 ,
    rightcolumn/width/.code = \def\rightwidth{#1} ,
    rightcolumn/width/.default = 0.4 ,
}

%%%%% Either use the following 3 macros or uncomment the      %%%%
%%%%% 3 macros below (which use columns instead of minipages) %%%%
%%%%% and comment out the first 3 macros                      %%%%
% ------- Macros using minipages - they work OK -------
\newrobustcmd*\leftcolumn[1][]{
    \pgfqkeys{/slide/leftcolumn}{#1}%
    \begin{minipage}{\leftwidth\linewidth}
}

\newrobustcmd*\rightcolumn[1][]{
    \end{minipage}\hfill
    \pgfqkeys{/slide/rightcolumn}{#1}
    \begin{minipage}{\rightwidth\linewidth}
}

\renewrobustcmd*\endcolumn{\end{minipage}}

% % ------- Macros using columns - they don't work -------
% \newrobustcmd*\leftcolumn[1][]{
%     \begin{columns} 
%         \pgfqkeys{/slide/leftcolumn}{#1}%
%         \column{\leftwidth\linewidth}
%         left width: |\leftwidth| * linewidth\\[1em]  % just some output
% }
%
% \newrobustcmd*\rightcolumn[1][]{
%     \pgfqkeys{/slide/rightcolumn}{#1}
%     \column{\rightwidth\linewidth}
%     right width: |\rightwidth| * linewidth\\[1em]  % \rightwidth is empty!
% } 
%
% \renewrobustcmd*\endcolumn{
%     \end{columns}
% }

\makeatother

\begin{document}

\begin{frame}[t]{}
    Using two minipages works, except for the default values: removing the [width=0.5] does not fall back to the default value of 0.6.\\[1em]

    \leftcolumn[width=0.5]  % does not work without [...]!
    Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. 

    \rightcolumn[width=0.35]
    Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. 

    \endcolumn  
\end{frame}    
\end{document}
2
  • IMHO if you want an easier life with columns in Beamer don't use it, but use the textpos package. See par 12.8 of the beamer user guide.
    – vi pa
    Commented Nov 8, 2019 at 10:08
  • The .default handler defines the value used if someone uses your key without value (ex: \leftcolumn[width]). The .inital handler defines the value used if your key is not used (ex: \leftcolumn). Commented Nov 8, 2019 at 15:45

2 Answers 2

2

As for your question, I would just set some initial values. Further, I would not introduce explicit macros, but use \pgfkeysvalueof instead.

\documentclass[11pt]{beamer}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{etoolbox}   
\makeatletter


\pgfkeys{
    /slide/.cd ,
    leftcolumn/width/.initial = 0.55 ,
    rightcolumn/width/.initial = 0.4 ,
}

% ------- Macros using minipages - they work OK -------
\newrobustcmd*\leftcolumn[1][]{%
    \pgfkeys{/slide/leftcolumn/.cd,#1}%
    \begin{minipage}{\pgfkeysvalueof{/slide/leftcolumn/width}\linewidth}
}

\newrobustcmd*\rightcolumn[1][]{%
    \end{minipage}\hfill
    \pgfkeys{/slide/rightcolumn/.cd,#1}%
    \begin{minipage}{\pgfkeysvalueof{/slide/rightcolumn/width}\linewidth}
}

\renewrobustcmd*\endcolumn{\end{minipage}}


\makeatother

\begin{document}

\begin{frame}[t]
    \frametitle{Setting explicit values}
    Using two minipages works.\\[1em]

    \leftcolumn[width=0.5]  % does not work without [...]!
    Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. 

    \rightcolumn[width=0.35]
    Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. 

    \endcolumn  
\end{frame}    

\begin{frame}[t]
    \frametitle{Setting no values will use the initial values}
    Using two minipages works.\\[1em]

    \leftcolumn  % works without [...]
    Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. 

    \rightcolumn
    Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. 

    \endcolumn  
\end{frame}    

\end{document}

enter image description here

Or with columns. (Bit more tricky because of TeX grouping.)

\documentclass[11pt]{beamer}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{etoolbox}   
\makeatletter


\pgfkeys{
    /slide/.cd ,
    leftcolumn/width/.initial = 0.55 ,
    rightcolumn/width/.initial = 0.4 ,
}

% ------- Macros using minipages - they work OK -------
\newrobustcmd*\leftcolumn[1][]{%
     \pgfkeys{/slide/leftcolumn/.cd,#1}%
    \begin{columns} 
    \column{\pgfkeysvalueof{/slide/leftcolumn/width}\linewidth}
        left width: |\pgfkeysvalueof{/slide/leftcolumn/width}| * linewidth\\[1em]  % just some output
}

\newrobustcmd*\rightcolumn[1][]{%
 \pgfkeys{/slide/rightcolumn/.cd,#1}% 
 \xdef\tmp{\pgfkeysvalueof{/slide/rightcolumn/width}}% smuggle out of group
 \column{\tmp\linewidth}
 \pgfkeys{/slide/rightcolumn/.cd,#1}% 
    right width: |\pgfkeysvalueof{/slide/rightcolumn/width}| * linewidth\\[1em]  % \rightwidth is empty!
} 

\renewrobustcmd*\endcolumn{%
    \end{columns}
}


\makeatother

\begin{document}

\begin{frame}[t]
    \frametitle{Setting explicit values}
    Using columns works.\\[1em]

    \leftcolumn[width=0.4]  % does not work without [...]!
    Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. 

    \rightcolumn[width=0.25]
    Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. 

    \endcolumn  
\end{frame}    

\begin{frame}[t]
    \frametitle{Setting no values will use the initial values}
    Using columns works.\\[1em]

    \leftcolumn  % works without [...]
    Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. 

    \rightcolumn
    Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. 

    \endcolumn  
\end{frame}    

\end{document}

enter image description here

8
  • Thanks, that solved the one problem concerning the minipage, but unfortunately, this still doesn't work in an columns environment (see the commented out variant above). With your solution, the /slide/rightcolumn/width now always equals to the .inital value. How could this be solved?
    – BanDoP
    Commented Nov 8, 2019 at 13:55
  • @BanDoP Maybe you can explain a bit what the purpose of the commented out stuff is? And no, /slide/rightcolumn/width does not always equal the .initial value. Try e.g. \rightcolumn[width=0.25].
    – user194703
    Commented Nov 8, 2019 at 13:57
  • Sure. It is just a beamer columns environment and therefore quite similar to what was done with the two minipages. The pgfkeys should be used to set the column width. Using the column env. with two columns, each of which will contain one minipage, makes h/v alignment easy.
    – BanDoP
    Commented Nov 8, 2019 at 14:07
  • @BanDoP You have two (times two)macros of the same name but with different contents. I did not touch the commented ones. Don't you think it would be better to give the ones that work with columns different names?
    – user194703
    Commented Nov 8, 2019 at 14:07
  • Oh, it's an "either or thing": just delete the first three macros that contain the minipage related code. I've added a comment to the original post.
    – BanDoP
    Commented Nov 8, 2019 at 14:21
0

With textpos package

    \documentclass[11pt]{beamer}
    \usepackage[utf8]{inputenc}
    \usepackage[T1]{fontenc}

    \usepackage[absolute,overlay
    %,showboxes
    ]{textpos}
    \TPGrid{1}{1}

    \begin{document}

    \begin{frame}
    \frametitle{columns with textpos package}
    \begin{textblock}{0.5}(0.05,0.1)%column with width of 0.5\paperwidth at 0.05 \paperwidth and 0.1\paperheight from the upper left corner
       Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
    \end{textblock}
    %
    \begin{textblock}{0.35}(0.6,0.2)%column with width of 0.35\paperwidth at 0.6\paperwidth and 0.2\paperheight from the upper left corner
        Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. 
    \end{textblock} 
    \end{frame}    
    \end{document}

enter image description here

You must log in to answer this question.

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