首页 > 解决方案 > LuaLaTeX:tabularx 环境中逐字环境的水平对齐

问题描述

首先,我完全意识到我的代码可能不是实现我想要做的事情的理想方式。但是我不是专业的 LaTeX 用户,这就是我想出来的方式。

我做了一个最小的例子,希望在编译时可以工作(编译器:LuaLaTeX)来显示我的问题。我正在尝试使用 tabularx-table 制作一个 beamer-frame,它一方面包含内联逐字环境,另一方面包含方程式环境。“Y”列类型是 tabularx 的“X”环境的修改形式,我在另一个 Stackoverflow 线程上找到了它。

现在的确切问题如下:我希望逐字表达式与方程表达式对齐,或者至少在每个单元格中垂直居中。

如前所述,我远非专家,我已经用尽了我所有的想法,所以我非常感谢任何形式的想法和建议。:)

\documentclass[c, 10pt]{beamer}

\usepackage{polyglossia}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{siunitx}
\usepackage{tabularx}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{siunitx}
\usepackage{placeins}
\usepackage{multirow}
\usepackage{booktabs}
\usepackage{verbatim}
\usepackage{fancyvrb}
\usepackage{nicefrac}
\usepackage{array}

\setdefaultlanguage{english}

\usetheme{JuanLesPins}
\usecolortheme{seahorse}

\newcolumntype{Y}{>{\centering\arraybackslash} X}

\begin{document}

\begin{frame}[fragile, allowframebreaks]{Symbols and Commands}
    \begin{block}{\centering \large{Division}}
        \begin{table}[h]
            \centering
            \renewcommand\baselinestretch{0.01}\selectfont
            \begin{tabularx}{\textwidth}{Y Y Y}
                \toprule
                \multicolumn{1}{m{.3\textwidth}}{\centering Code} & \multicolumn{2}{m{.6\textwidth}}{\centering Examples}\\
                \midrule 
                \verb|\dfrac{a}{b}| & 
                {\begin{equation*}
                    \dfrac{a}{b}
                    \end{equation*}} & 
                {\begin{equation*}
                    \mathrm{e}^{\dfrac{1}{k_BT}}
                    \end{equation*}} \\
                \verb|\frac{a}{b}| &
                {\begin{equation*}
                    \frac{a}{b}
                    \end{equation*}} &
                {\begin{equation*}
                    \mathrm{e}^{\frac{1}{k_BT}}
                    \end{equation*}} \\
                \verb|\nicefrac{a}{b}| &
                {\begin{equation*}
                    \nicefrac{a}{b}
                    \end{equation*}} &
                {\begin{equation*}
                    \mathrm{e}^{\nicefrac{1}{k_BT}}
                    \end{equation*}} \\
                \bottomrule
            \end{tabularx}
        \end{table}
    \end{block}
\end{frame}    

\end{document}

标签: latextabularverbatim

解决方案


要将未编号的方程式放在表格中,我宁愿使用内联数学而不是方程式环境。要获得与方程式中相同的分数渲染,请添加 \displaystyle.

无关:

  • 不要多次加载包

  • fragile, allowframebreaks除非框架确实需要它们,否则不要使用

  • 浮动说明符[H]在没有浮动机制的文档类中没有意义

  • 您不需要\centering在投影仪表中,默认情况下它们是居中的

  • 语法\large{...}错误,\large是一个开关,不带参数,所以应该是\large Division. 无论如何,最好不要将格式化指令放在宏参数中,而是设置适当的投影仪模板来控制块标题的字体


\documentclass[c, 10pt]{beamer}

%\usepackage{polyglossia}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{siunitx}
\usepackage{tabularx}
%\usepackage{amsmath}
%\usepackage{amssymb}
%\usepackage{siunitx}
%\usepackage{placeins}
\usepackage{multirow}
\usepackage{booktabs}
%\usepackage{verbatim}
%\usepackage{fancyvrb}
\usepackage{nicefrac}
\usepackage{array}


%\setdefaultlanguage{english}

\usetheme{JuanLesPins}
\usecolortheme{seahorse}

\newcolumntype{Y}{>{\centering\arraybackslash} X}

\setbeamerfont{block title}{size=\large}

\begin{document}

\begin{frame}
    \frametitle{Symbols and Commands}
    \begin{block}{\centering Division}
        \begin{table}
%            \centering
%            \renewcommand\baselinestretch{0.01}\selectfont
            \begin{tabularx}{\textwidth}{Y Y Y}
                \toprule
                 Code & \multicolumn{2}{c}{Examples}\\
                \midrule 
                \verb|\dfrac{a}{b}| & 
                $\displaystyle\dfrac{a}{b}$ & 
                $\displaystyle\mathrm{e}^{\dfrac{1}{k_BT}}$ \\\addlinespace
                \verb|\frac{a}{b}| &
                $\displaystyle\frac{a}{b}$ &
                $\displaystyle\mathrm{e}^{\frac{1}{k_BT}}$ \\\addlinespace
                \verb|\nicefrac{a}{b}| &
                $\displaystyle\nicefrac{a}{b}$ &
                $\displaystyle\mathrm{e}^{\nicefrac{1}{k_BT}}$ \\
                \bottomrule
            \end{tabularx}
        \end{table}
    \end{block}
\end{frame}    

\end{document}

推荐阅读