3

Using the acolumns environment from this question I discovered that the horizontal alignment of the columns is modified in same way. I'm using it for a poster and the difference becomes quite notable. This example should show the vertical misalignment between blocks

\documentclass{beamer}

\usecolortheme{rose}

\usepackage{environ}% Required for \NewEnviron, i.e. to read the whole body of the environment
\makeatletter

\newcounter{acolumn}%  Number of current column
\newlength{\acolumnmaxheight}%   Maximum column height


% `column` replacement to measure height
\newenvironment{@acolumn}[1]{%
    \stepcounter{acolumn}%
    \begin{lrbox}{\@tempboxa}%
    \begin{minipage}{#1}%
}{%
    \end{minipage}
    \end{lrbox}
    \@tempdimc=\dimexpr\ht\@tempboxa+\dp\@tempboxa\relax
    % Save height of this column:
    \expandafter\xdef\csname acolumn@height@\roman{acolumn}\endcsname{\the\@tempdimc}%
    % Save maximum height
    \ifdim\@tempdimc>\acolumnmaxheight
        \global\acolumnmaxheight=\@tempdimc
    \fi
}

% `column` wrapper which sets the height beforehand
\newenvironment{@@acolumn}[1]{%
    \stepcounter{acolumn}%
    % The \autoheight macro contains a \vspace macro with the maximum height minus the natural column height
    \edef\autoheight{\noexpand\vspace*{\dimexpr\acolumnmaxheight-\csname acolumn@height@\roman{acolumn}\endcsname\relax}}%
    % Call original `column`:
    \begin{orig@column}{#1}%
}{%
    \end{orig@column}%
}

% Save orignal `column` environment away
\let\orig@column\column
\let\endorig@column\endcolumn

% `columns` variant with automatic height adjustment
\NewEnviron{acolumns}[1][]{%
    % Init vars:
    \setcounter{acolumn}{0}%
    \setlength{\acolumnmaxheight}{0pt}%
    \def\autoheight{\vspace*{0pt}}%
    % Set `column` environment to special measuring environment
    \let\column\@acolumn
    \let\endcolumn\end@acolumn
    \BODY% measure heights
    % Reset counter for second processing round
    \setcounter{acolumn}{0}%
    % Set `column` environment to wrapper
    \let\column\@@acolumn
    \let\endcolumn\end@@acolumn
    % Finally process columns now for real
    \begin{columns}[#1]%
        \BODY
    \end{columns}%
}
\makeatother

\begin{document}
\begin{frame}{A frame}
  \begin{acolumns}[t]
    \begin{column}{0.5\linewidth}
      \begin{block}{A block}
        Hello
        \autoheight
      \end{block}
    \end{column}
    \begin{column}{0.5\linewidth}
      \begin{block}{Another block}
        This one has a larger height since it has an itemize
        \begin{itemize}
        \item item a
        \end{itemize}
        \autoheight
      \end{block}
    \end{column}
  \end{acolumns}

  \begin{columns}[t]
    \begin{column}{0.5\linewidth}
      \begin{block}{A block}
        Hello
      \end{block}
    \end{column}
    \begin{column}{0.5\linewidth}
      \begin{block}{Another block}
        This one has a larger height since it has an itemize
        \begin{itemize}
        \item item a
        \end{itemize}
      \end{block}
    \end{column}
  \end{columns}
\end{frame}

\end{document}

is there some spurious space that introduces it?

EDIT

add

\usepackage{tikz}
%...

\tikz[remember picture,overlay] \draw [red,xshift=1em] (current page.north west) ++(1em,0) |- (current page.south west);

at the end of the frame to better see the misalignment.

example

upper left block crosses the red line, bottom one doesn't!

8
  • The two blocks on the left appear to be vertically aligned with the two blocks on the right. Can you add some more detail as to exactly what the problem is -- perhaps with an image that shows it. Commented May 4, 2012 at 15:21
  • i'm sorry, i meant to say that the horizontal alignment between the top left and the bottom left (and between top right and bottom right) is wrong Commented May 4, 2012 at 16:02
  • There are two spurious spaces in the code around lines 18 and 19: ` \end{minipage}%<< \end{lrbox}%<< ` but I couldn't work out where you are seeing the bad alignment so I don't know if this fixes anything Commented May 4, 2012 at 16:08
  • If you add a % on line 74: end{column}% the horizontal alignment seems fine. Is this what you are referring to? Commented May 4, 2012 at 16:27
  • yeah, that's it! why do i need to add that % only for the acolumns environment? where's the spurious space? Commented May 4, 2012 at 17:13

1 Answer 1

3

You should change

    % Call original `column`:
    \begin{orig@column}{#1}%
}{%
    \end{orig@column}%
}

to

    % Call original `column`:
    \orig@column{#1}%
}{%
    \endorig@column
}

The inner environment defeats latex's space gobbling code. You could re-insert it by using \ignorespacesafterend at the end of the end code, but just not using teh inner environment is simpler.

1
  • Thanks David, for figuring the issue out. I now updated my original code accordantly. Commented May 7, 2012 at 10:10

You must log in to answer this question.

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