如何在表格环境中垂直对齐格式化的文本和多行方程式?

如何在表格环境中垂直对齐格式化的文本和多行方程式?

在这个工作示例中,我使用了 tabular{}、aligned{} 和 makecell{} 在表格中插入格式化文本和多行方程式,如图所示。但检查最终输出后,文本和方程式在每个单元格中并未垂直对齐。有没有办法将文本和方程式在每个单元格中垂直对齐。我搜索了之前关于垂直对齐的答案,解决方案似乎因单元格的内容、文本、图像、方程式、图形和要使用的软件包的首选而有所不同。有没有通用的解决方案?

\documentclass[table]{beamer}
\usetheme{Boadilla}

\usepackage{amsmath}
\usepackage{xcolor} 
\usepackage{makecell}
\usepackage{array}
\usepackage{mathtools}

\begin{document}

\begin{frame}{The Four Fourier Transforms}
    \begin{table}[]
    \setlength{\tabcolsep}{10pt} % Default value: 6pt
    \renewcommand{\arraystretch}{4.5} % Default value: 1
    \begin{center}
    \caption{\Large The Four Fourier Tranforms}
    \label{tab:table41}
    \begin{tabular}{| c | c |}
        \hline
        \makecell{ \textcolor{orange}{\Large Fourier Series} \\ {\Large for} \\ \textcolor{orange}{\Large Periodic, \textbf{Continuous-}}\\ \textcolor{orange}{\Large \textbf{Time} }{\Large Signals} } & 
        \makecell{ \textcolor{blue}{\Large Fourier Transform} \\ {\Large for} \\ \textcolor{blue}{\Large Aperiodic} \textcolor{orange}{\Large \textbf{Continuous-}}\\\textcolor{orange}{\Large \textbf{Time} }{\Large Signals} }\\
        \hline
        \makecell{ \textcolor{orange}{\Large Fourier Series} \\ {\Large for} \\ \textcolor{orange}{\Large Periodic }\textcolor{yellow}{\Large \textbf{Discrete-}}\\ \textcolor{yellow}{\Large \textbf{Time} }{\Large Signals} } & 
        \makecell{ \textcolor{blue}{\Large Fourier Transform} \\ {\Large for} \\ \textcolor{blue}{\Large Aperiodic} \textcolor{yellow}{\Large \textbf{Discrete-}}\\\textcolor{yellow}{\Large \textbf{Time} }{\Large Signals} }\\
        \hline
    \end{tabular}
    \end{center}
\end{table}
\end{frame}

\begin{frame}{The Four Fourier Transforms}
\begin{table}[]
    \setlength{\tabcolsep}{10pt} % Default value: 6pt
    \renewcommand{\arraystretch}{5.5} % Default value: 1
    \begin{center}
    \caption{\Large The Four Fourier Tranforms}
    \label{tab:table42}
    \begin{tabular}{| >{$}c<{$} | >{$}c<{$} |}
        \hline
        \begin{aligned}
            C_k & = \dfrac{1}{T}\int_{T_0}f(t)e^{-jk\omega_0 t}dt \\
            f(t) & = \sum_{k=-\infty}^{\infty}C_k e^{jk\omega_0 t}
        \end{aligned}
        &
        \begin{aligned}
            F(\omega) &=  \int_{-\infty}^{\infty}f(t)e^{-j\omega t}dt
            \\
            f(t) &= \sum_{-\infty}^{\infty}F(\omega)e^{j\omega t}d\omega
        \end{aligned} \\
        \hline
        \begin{aligned}
            c_k &=  \dfrac{1}{N}x(n)e^{-j2\pi kn/N}dt
            \\
            x(n) &= \sum_{k=0}^{N-1}c_k e^{j2\pi kn/N}
        \end{aligned} 
        &
        \begin{aligned}
            X(\omega) &=  \sum_{n=-\infty}^{\infty}x(n)e^{-j\omega n}
            \\
            x(n) &= \dfrac{1}{2\pi}\int_{2\pi}X(\omega)e^{j\omega n}
        \end{aligned} \\
        \hline
    \end{tabular}
    \end{center}
\end{table}
\end{frame}
\end{document}

答案1

  • 导致您问题的是代码行\renewcommand{\arraystretch}{4.5} % Default value: 1。只需将其删除即可。
  • 答案仅考虑带有方程表的第二框架。
  • beamer加载xcolormathtools加载amsmath,因此无需再次加载它们。
  • 在数学环境中使用表格代替array(代码略短)
  • 对于额外的垂直空间,makegapedcells在包中定义makecell
\documentclass[table]{beamer}
\usetheme{Boadilla}

\usepackage{makecell}
\usepackage{mathtools}

\begin{document}
\begin{frame}
\frametitle{The Four Fourier Transforms}
    \begin{table}
    \setcellgapes{3pt}
    \makegapedcells
\caption{\Large The Four Fourier Transforms}
\label{tab:table42}
\vspace{-\abovedisplayskip}
    \[
\begin{array}{| c | c |}
        \hline
\begin{aligned}
C_k  & = \dfrac{1}{T}\int_{T_0}f(t)e^{-jk\omega_0 t}dt \\
f(t) & = \sum_{k=-\infty}^{\infty}C_k e^{jk\omega_0 t}
\end{aligned}
    &   \begin{aligned}
F(\omega) & =  \int_{-\infty}^{\infty}f(t)e^{-j\omega t}dt\\
f(t)      & = \sum_{-\infty}^{\infty}F(\omega)e^{j\omega t}d\omega
        \end{aligned}   \\
        \hline
\begin{aligned}
c_k & =  \dfrac{1}{N}x(n)e^{-j2\pi kn/N}dt \\
x(n) & = \sum_{k=0}^{N-1}c_k e^{j2\pi kn/N}
\end{aligned}
    &   \begin{aligned}
X(\omega) & = \sum_{n=-\infty}^{\infty}x(n)e^{-j\omega n} \\
x(n)      & = \dfrac{1}{2\pi}\int_{2\pi}X(\omega)e^{j\omega n}
        \end{aligned} \\
    \hline
\end{array}
    \]
    \end{table}
\end{frame}
\end{document}

在此处输入图片描述

附录: 而是以行内方式使用 display-math 环境,添加了用于\arraycolsep在单元格内容周围留出更多水平空间的设置,定义了两个新命令,用于在函数f和之后获得更好的间距括号x

在投影机方面有更一致定义的字幕字体:


\documentclass[table]{beamer}
\usetheme{Boadilla}
    \setbeamerfont{caption}{size=\large}  % <---

\usepackage{makecell}
\newcommand\ft{f\,(t)} % <---
\newcommand\xn{x\,[n]} % or if you more prefer x\left(n\right) <---

\begin{document}

\begin{frame}
\frametitle{The Four Fourier Transforms}
    \begin{table}
    \setcellgapes{3pt}
    \makegapedcells

\caption{The Four Fourier Transforms}
\label{tab:table42}
    $\setlength\arraycolsep{16pt} % <---
     \displaystyle 
\begin{array}{| c | c |}
        \hline
\begin{aligned}
C_k             & = \frac{1}{T}\int_{T_0} \ft e^{-jk\omega_0 t}dt \\
f\left(t\right) & = \sum_{k=-\infty}^{\infty}C_k e^{\,jk\omega_0 t}
\end{aligned}
    &   \begin{aligned}
F(\omega)   & =  \int_{-\infty}^{\infty} \ft e^{-j\omega t}dt\\
\ft         & = \sum_{-\infty}^{\infty}F(\omega) e^{\,j\omega t}d\omega
        \end{aligned}   \\
        \hline
\begin{aligned}
c_k & =  \frac{1}{N} \xn e^{-j2\pi kn/N}dt \\
\xn & = \sum_{k=0}^{N-1}c_k e^{\,j2\pi kn/N}
\end{aligned}
    &   \begin{aligned}
X(\omega) & = \sum_{n=-\infty}^{\infty}\xn e^{-j\omega n} \\
\xn       & = \frac{1}{2\pi}\int_{2\pi}X(\omega) e^{\,j\omega n}
        \end{aligned} \\
    \hline
\end{array}
    $
    \end{table}
\end{frame}
\end{document}

在此处输入图片描述

相关内容