如何在投影仪列中垂直对齐图像?

如何在投影仪列中垂直对齐图像?

如何垂直对齐 的内容beamer column?在下面的例子中,我希望第二列中的规则垂直居中。

我可以使用\begin{columns}[c],但这会使所有列垂直对齐。我仍然希望第一列和第三列顶部对齐。我也尝试\vfill在不同的地方添加,但没有效果。

在此处输入图片描述

\documentclass[pdf]{beamer}
\begin{document}
\begin{frame}
    \begin{columns}[T]
        \begin{column}{0.33\linewidth}
            This is the first column. This is the first column. 
        \end{column}
        \begin{column}{0.33\linewidth}
            \centering
            \rule{\linewidth}{1cm}
        \end{column}
        \begin{column}{0.33\linewidth}
            This is the third column. This is the third column. This is the third column. This is the third column. This is the third column. This is the third column. This is the third column. This is the third column. 
        \end{column}
    \end{columns}
\end{frame}
\end{document}

答案1

无需猜测移位值。您可以让 LaTeX 为您完成所有计算:使用minipages,测量左右minipages 的总高度,选择最大高度,然后在可选参数中使用此值来minipage获得所需的对齐方式。

\TCTcolumns将做到这一点;它有三个强制性参数:

\TCTcolumns{<column 1 contents>}{<column 2 contents>}{<column 3 contents>}

代码:

\documentclass{beamer}

\newsavebox\myboxa
\newsavebox\myboxb
\newlength\myhta
\newlength\mydpa
\newlength\myhtb
\newlength\mydpb
\newlength\maxht

\newcommand\TCTcolumns[3]{%
\begin{lrbox}{\myboxa}
  \begin{minipage}{0.3\linewidth}
  #1
  \end{minipage}%
\end{lrbox}%
\begin{lrbox}{\myboxb}
  \begin{minipage}{0.3\linewidth}
  #3
  \end{minipage}%
\end{lrbox}% 
\settoheight\myhta{\usebox\myboxa}%
\settodepth\mydpa{\usebox\myboxa}%
\addtolength\myhta{\mydpa}%
\settoheight\myhtb{\usebox\myboxb}%
\settodepth\mydpb{\usebox\myboxb}%
\addtolength\myhtb{\mydpb}%
\setlength\maxht{\myhta}%
\ifdim\myhtb>\myhta
  \setlength\maxht{\myhtb}%
\fi
\begin{minipage}[t][\maxht][t]{0.3\linewidth}
  #1
\end{minipage}\hfill
\begin{minipage}[t][\maxht][c]{0.3\linewidth}
  #2
\end{minipage}\hfill
\begin{minipage}[t][\maxht][t]{0.3\linewidth}
  #3
\end{minipage}%
}

\begin{document}

\begin{frame}
\TCTcolumns{This is the first column. This is the first column.}{\centering\raisebox{0.5\height}{\rule{\linewidth}{1cm}}}{This is the third column. This is the third column. This is the third column. This is the third column. This is the third column. This is the third column. This is the third column. This is the third column.}
\end{frame}

\end{document}

结果:

在此处输入图片描述

答案2

如果您不介意使用包来完成这项工作,您可以使用tcolorbox。请注意,您需要全新的版本3.30 (2014/11/17)

\documentclass[pdf]{beamer}
\usepackage[many]{tcolorbox}
\begin{document}
\begin{frame}
  \begin{tcbitemize}[raster columns=3,raster equal height,blanker,
    raster column skip=5mm,raster left skip=-5mm,raster right skip=-5mm,
    flushleft upper]
  \tcbitem
    This is the first column. This is the first column.
  \tcbitem[valign=center]
    \rule{\linewidth}{1cm}
  \tcbitem
    This is the third column. This is the third column. This is the third column. This is the third column. This is the third column. This is the third column. This is the third column. This is the third column.
  \end{tcbitemize}
\end{frame}
\end{document}

经过两次编译,结果是:

在此处输入图片描述

答案3

这很容易,使用\parbox。您将必须对规则的实际垂直位移进行一些肮脏的调整。

在此处输入图片描述

\documentclass[pdf]{beamer}
\begin{document}
\begin{frame}
\begin{columns}[T]
    \begin{column}{0.33\linewidth}
        This is the first column. This is the first column. 
    \end{column}
    \begin{column}{0.33\linewidth}
        \centering
    \parbox{\linewidth}{\vspace{2cm}
        \rule{\linewidth}{1cm}}
    \end{column}
    \begin{column}{0.33\linewidth}
        This is the third column. This is the third column. This is the third column. This is the third column. This is the third column. This is the third column. This is the third column. This is the third column. 
    \end{column}
\end{columns}
\end{frame}
\end{document}

相关内容