兩列中的區塊對齊問題?

兩列中的區塊對齊問題?

考慮以下投影機框架代碼:

\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的總高度是)字元的總高度。因此A\strut比 a 稍高\mathstrut。無論哪種方式,\strut和都\mathstrut為左側塊提供了足夠的深度。

一般來說,可能需要提供支柱兩個都左側和右側範例區塊環境,特別是如果一個區塊包含具有上行字母但沒有下行字母的單字(例如,left, black),而另一個區塊包含具有下行字母但沒有上行字母的單字(例如,green, uvwxyz)。

在此輸入影像描述

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

相關內容