3

When I place some columns using beamer's columns environment, they are equally spaced horizontally by default, ignoring margins (i.e. the spacing between columns is the same as the spacing to the frame edge). However, when I change their total width using the totalwidth parameter, the box containing all the columns is now left aligned (i.e. the first column's left edge is on the left edge of the type area and the last column's right edge is totalwidth to the right from there).

How can I instead center the column-box in the type area (or, equivalently, on the page)?

\centering has no effect. I could of course wrap the whole thing in a minipage, but that somewhat defeats the point of setting totalwidth in my eyes. Also, since columns will still compensate for the frame margins even in the minipage, I'd still have to use totalwidth (or equivalently onlytextwidth) inside the minipage. I feel like I'm missing something here; there should be an easier way, right?

MWE:

\documentclass{beamer}

\def\examplecols#1{%
  \begin{column}{#1}
    \rule{\textwidth}{1ex}
  \end{column}
  \begin{column}{#1}
    \rule{\textwidth}{1ex}
  \end{column}
}

\begin{document}

\begin{frame}
  % Default behavior: equal spacing ignoring margins.
  \begin{columns}
    \examplecols{.5\textwidth}
  \end{columns}
  
  % Text width, for reference.
  \rule{\textwidth}{1ex}

  % Custom totalwidth: \centering has no effect.
  \centering
  \begin{columns}[totalwidth=.45\textwidth]
    \examplecols{.2\textwidth}
  \end{columns}
  
  \vfill
  
  % With a minipage (0.2 / 0.45 = 0.4444...):
  \begin{minipage}{.45\textwidth}
    % Default behavior: Still compensating for margins.
    \begin{columns}
      \examplecols{.4444\textwidth}
    \end{columns}
    
    % Text width, for reference.
    \rule{\textwidth}{1ex}
    
    % Custom totalwidth: This is what I actually want.
    \begin{columns}[totalwidth=\textwidth]
      \examplecols{.4444\textwidth}
    \end{columns}
  \end{minipage}
\end{frame}

\end{document}

MWE output

1 Answer 1

2

You could redefine the totalwidth key like this:

\documentclass{beamer}

\makeatletter
\define@key{beamer@col}{totalwidth}{%
  \def\beamer@colentrycode{\hfill\hbox to#1\bgroup\ignorespaces}%
  \def\beamer@colexitcode{\unskip\egroup\hfill}}
\makeatother

\def\examplecols#1{%
  \begin{column}{#1}
    \rule{\textwidth}{1ex}
  \end{column}
  \begin{column}{#1}
    \rule{\textwidth}{1ex}
  \end{column}
}

\begin{document}

\begin{frame}

  \begin{columns}[totalwidth=.45\textwidth]
    \examplecols{.2\textwidth}
  \end{columns}
  
\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 .