7

My typical columns environment looks like this

\begin{columns}[onlytextwidth]
        ...
\end{columns}

Is there a way to set the [onlytextwidth] for the whole document, so that I don't have to type it every time?

MWE

\documentclass{beamer}

\begin{document}
    \begin{frame}
        \begin{columns}[onlytextwidth]
            \begin{column}{.5\textwidth}
                \rule{\textwidth}{1cm}
            \end{column}
            \begin{column}{.5\textwidth}
                \rule{\textwidth}{1cm}
            \end{column}            
        \end{columns}

        \begin{columns}
            \begin{column}{.5\textwidth}
                \rule{\textwidth}{1cm}
            \end{column}
            \begin{column}{.5\textwidth}
                \rule{\textwidth}{1cm}
            \end{column}            
        \end{columns}       

    \end{frame}
\end{document}

enter image description here

  • Your example doesn't show any difference between using [onlytextwidth] and removing the option. – Ulrike Fischer Oct 1 '14 at 9:31
5

You may define a new environment (columnsotw in the example below) that uses onlytextwidth as default option... or you may use the predefined environment columnsonlytextwidth (without any other options)

enter image description here

\documentclass{beamer}
\usepackage{lipsum}

\newenvironment{columnsotw}[1][]{\columns[onlytextwidth,#1]}{\endcolumns}

\def\cola{Abc def ghi jkl mno pqr stu vwx z. Abc def ghi jkl mno pqr stu vwx z.}
\def\colb{Abc def ghi jkl.}

\begin{document}
\begin{frame}[fragile]
  \begin{columns}[onlytextwidth,b]
    \column{.4\linewidth}
    \cola
    \column{.4\linewidth}
    \colb
  \end{columns}
  \vfill
  \begin{columnsonlytextwidth}% [b] ???
    \column{.4\linewidth}
    \cola
    \column{.4\linewidth}
    \colb
  \end{columnsonlytextwidth}
  \vfill
  \begin{columnsotw}[b]
    \column{.4\linewidth}
    \cola
    \column{.4\linewidth}
    \colb
  \end{columnsotw}
  \vfill
  \begin{columns}[b]
    \column{.4\linewidth}
    \cola
    \column{.4\linewidth}
    \colb
  \end{columns}
\end{frame}
\end{document}
  • There exists already such an evironment with the name columnsonlytextwidth – Ulrike Fischer Oct 1 '14 at 14:43
  • @UlrikeFischer Hum... Compare \begin{columnsotw}[b]... and \begin{columnsonlytextwidth}[b].... ;-) – Paul Gaborit Oct 1 '14 at 20:49
2

Instead of creating a new environment, another possibility is to redefine the columns-environment

\documentclass{beamer}

\makeatletter
\long\def\beamer@newenvnoopt#1#2#3#4{%
    \expandafter\renewcommand\expandafter<\expandafter>\csname#1\endcsname[#2]{#3}%<- here
    \expandafter\long\expandafter\def\csname end#1\endcsname{#4}%
}
\long\def\beamer@newenvopt#1#2[#3]#4#5{%
    \expandafter\renewcommand\expandafter<\expandafter>\csname#1\endcsname[#2][#3]{#4}%<- here
    \expandafter\long\expandafter\def\csname end#1\endcsname{#5}%
}

\renewenvironment<>{columns}[1][]{%
    \begin{actionenv}#2%
        \def\beamer@colentrycode{%
            \hbox to\textwidth\bgroup%
            \leavevmode%
            \hskip-\beamer@leftmargin%
            \nobreak%
            \beamer@tempdim=\textwidth%
            \advance\beamer@tempdim by\beamer@leftmargin%
            \advance\beamer@tempdim by\beamer@rightmargin%
            \hbox to\beamer@tempdim\bgroup%
            \hbox{}\hfill\ignorespaces}%
        \def\beamer@colexitcode{\egroup%
            \nobreak%
            \hskip-\beamer@rightmargin\egroup}%
        \ifbeamer@centered\setkeys{beamer@col}{c}\else\setkeys{beamer@col}{t}\fi%
        \setkeys{beamer@col}{#1, onlytextwidth}% added "onlytextwidth"
        \par%
        \beamer@colentrycode%
        \def\beamer@colclose{}\ignorespaces}%
    {\beamer@colclose\def\beamer@colclose{}\beamer@colexitcode\end{actionenv}}%
\makeatother

\begin{document}
    \begin{frame}
        \begin{columns}[onlytextwidth]
            \begin{column}{.5\textwidth}
                \rule{\textwidth}{1cm}
            \end{column}
            \begin{column}{.5\textwidth}
                \rule{\textwidth}{1cm}
            \end{column}            
        \end{columns}

        \begin{columns}
            \begin{column}{.5\textwidth}
                \rule{\textwidth}{1cm}
            \end{column}
            \begin{column}{.5\textwidth}
                \rule{\textwidth}{1cm}
            \end{column}            
        \end{columns}       

    \end{frame}
\end{document}

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.