两列块对齐问题?

两列块对齐问题?

考虑以下投影仪框架的代码:

\begin{frame}{Test}
\begin{block}{Single column}
\justifying
This is a block.
\end{block}
\begin{columns}[onlytextwidth]
\begin{column}{0.45\textwidth}
\begin{exampleblock}{Left}
\justifying
This is the first column.
\end{exampleblock}
\end{column}
\begin{column}[right]{0.45\textwidth}
\begin{exampleblock}{Right}
\justifying
This is the second column.
\end{exampleblock}
\end{column}
\end{columns}
\end{frame}

它产生以下结果: 插图

问题是右侧块没有与整个文本宽度右对齐。

如何正确对齐?

编辑:

我加载了以下包:

\usepackage{marvosym} %
\usepackage{ragged2e} % define justifying
\usepackage{hyperref} %
\usepackage{transparent} %

答案1

正如@barbarabeeton 在评论中所观察到的,有必要在左侧环境中插入类似的内容\strut--也会这样做 -- ,即包含单词 的环境中,它不包含带有降部字母的字母 -- 而包含。\mathstrutexampleblockLeftRight

在 LaTeX 内核中,\strut被定义为零宽度,因此不可见的垂直线,其高度0.7\baselineskip和深度为0.3\baselineskip;因此其总高度等于\baselineskip。相反, a\mathstrut的总高度是)字符的高度。\strut因此 A 略高于 a 。无论哪种方式,和\mathstrut都为左侧块提供了足够的深度。\strut\mathstrut

一般来说,可能需要在两个都左侧和右侧的示例块环境,特别是当一个块包含具有上升部但没有下降部的单词(例如,leftblack)并且另一个块包含具有下降部但没有上升部的单词(例如,greenuvwxyz)时。

在此处输入图片描述

\documentclass{beamer}
\usetheme{Madrid}
\usepackage{marvosym} %
\usepackage{ragged2e} % define justifying
\usepackage{transparent} %
\usepackage{hyperref} %
\begin{document}
\begin{frame}{Test}
\begin{block}{Single column}
\justifying
This is a block.
\end{block}
\begin{columns}[onlytextwidth]
\begin{column}{0.45\textwidth}
\begin{exampleblock}{Left\strut}
\justifying
This is the first column.
\end{exampleblock}
\end{column}
\begin{column}{0.45\textwidth}
\begin{exampleblock}{Right}
\justifying
This is the second column.
\end{exampleblock}
\end{column}
\end{columns}
\end{frame}
\end{document} 

答案2

在此处输入图片描述

\documentclass{beamer}
\usetheme{Boadilla}

\newsavebox{\squaredblocktext}
\setbeamertemplate{block begin}{
    \par\vskip\medskipamount%
    \makebox[\dimexpr\textwidth-1.5ex\relax][l]{%
        \begin{beamercolorbox}[colsep*=.75ex]{block title}
            \usebeamerfont*{block title}\insertblocktitle%
        \end{beamercolorbox}}%
        \begin{lrbox}{\squaredblocktext}%
            \begin{minipage}[t]{\textwidth}%
                \ifbeamercolorempty[bg]{block body}{\vskip-.25ex}{\vskip-.75ex}\vbox{}%
}

\setbeamertemplate{block end}{
            \end{minipage}%
        \end{lrbox}%
        {\parskip0pt\par}%
        \ifbeamercolorempty[bg]{block title}{}
        {\ifbeamercolorempty[bg]{block body}{}{\nointerlineskip\vskip-0.5pt}}%
        \usebeamerfont{block body}%
        \makebox[\dimexpr\textwidth-1.5ex\relax][l]{%
        \begin{beamercolorbox}[colsep*=.75ex,vmode]{block body}%
            \usebox{\squaredblocktext}
        \end{beamercolorbox}%
    }\vskip\smallskipamount%
}

\setbeamertemplate{block example begin}{
    \par\vskip\medskipamount%
    \makebox[\dimexpr\textwidth-1.5ex\relax][l]{%
        \begin{beamercolorbox}[colsep*=.75ex]{block title example}
            \usebeamerfont*{block titleexample}\insertblocktitle%
        \end{beamercolorbox}}%
        \begin{lrbox}{\squaredblocktext}%
            \begin{minipage}[t]{\textwidth}%
                \ifbeamercolorempty[bg]{block body example}{\vskip-.25ex}{\vskip-.75ex}\vbox{}%
            }

\setbeamertemplate{block example end}{
            \end{minipage}%
        \end{lrbox}%
        {\parskip0pt\par}%
        \ifbeamercolorempty[bg]{block title example}{}
        {\ifbeamercolorempty[bg]{block body example}{}{\nointerlineskip\vskip-0.5pt}}%
        \usebeamerfont{block body example}%
        \makebox[\dimexpr\textwidth-1.5ex\relax][l]{%
            \begin{beamercolorbox}[colsep*=.75ex,vmode]{block body example}%
                \usebox{\squaredblocktext}
            \end{beamercolorbox}%
        }\vskip\smallskipamount%
}

\begin{document}
    \begin{frame}{Test}
        \begin{block}{Single column}
            This is a block.
        \end{block}
        \begin{columns}[onlytextwidth]
            \begin{column}{0.45\textwidth}
                \begin{exampleblock}{Left}
                    This is the first column.
                \end{exampleblock}
            \end{column}
            \begin{column}{0.45\textwidth}
                \begin{exampleblock}{Right}
                    This is the second column.
                \end{exampleblock}
            \end{column}
        \end{columns}
    \end{frame}
\end{document}

相关内容