acolumns 环境修改列宽

acolumns 环境修改列宽

使用acolumns来自的环境这个问题我发现列的水平对齐方式也以相同的方式进行了修改。我将其用于海报,差异变得非常明显。此示例应显示块之间的垂直错位

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

是否存在一些虚假的空间来引入它?

编辑

添加

\usepackage{tikz}
%...

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

在框架的末端可以更好地看到错位。

例子

左上角的方块越过了红线,而左下角的方块没有!

答案1

你应该改变

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

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

\ignorespacesafterend内部环境可以消除 latex 占用空间的代码。您可以在结束代码的末尾使用 重新插入它,但不使用内部环境更简单。

相关内容