Beamer 中显示表格最后一列时出错

Beamer 中显示表格最后一列时出错

使用以下代码,我无法弄清楚为什么使用代码时不显示最后一列文本

\centering {\textcolor{black} {\bf receptors}}`

给出错误信息

! Misplaced \noalign.
\hline ->\noalign 
{\ifnum 0=`}\fi \penalty \@M \futurelet \@let@token \LT@@h...
l.38     \end{frame}
?

但只有使用代码时才能显示

\multicolumn{1}{c|}{\parbox {.29\textwidth}{\centering {\textcolor{black} {\bf receptors}}}}

梅威瑟:

\documentclass{beamer}
\setbeamertemplate{navigation symbols}{}
\usepackage{verbatim}
\usepackage{longtable}
\usepackage{colortbl}
\usepackage{multicol}
\usepackage{multirow}
\begin{document}
\begin{frame}[t]
\frametitle{\bf Types of ...}
\begin{table}
\begin{minipage}[c]{1.\textwidth}
{
\begin{center}
\begin{longtable}[!htp]{|m{.16\textwidth}|m{.16\textwidth}|m{.28\textwidth}|}\hline
\centering {\textcolor{black} {\bf hello}} & 
\centering {\textcolor{blue} {\bf hello}}\\
{\textcolor{green} {\bf hello}} &
%\centering {\textcolor{black} {\bf receptors}}
\multicolumn{1}{c|}{\parbox {.29\textwidth}{\centering {\textcolor{black} {\bf receptors}}}}
\\ \hline
\centering {\textcolor{black} {\bf hello}} & 
\centering {\textcolor{blue} {\bf hello}}\\
{\textcolor{green} {\bf hello}} &
\\ \hline
\centering {\textcolor{black} {\bf hello}} & 
\centering {\textcolor{blue} {\bf hello}}\\
{\textcolor{green} {\bf hello}} &
\\ \hline
\end{longtable}
\end{center}
}
\end{minipage}
\end{table}
\end{frame}
\end{document} 

在此处输入图片描述

答案1

代码似乎不必要地复杂化,我会写出这样的表格:

\documentclass{beamer}

\setbeamertemplate{navigation symbols}{}
\setbeamerfont{frametitle}{series=\bfseries}

\usepackage{array}
\newcolumntype{C}[1]{>{\centering\arraybackslash\hspace{0pt}}m{#1}}

\begin{document}

\begin{frame}[t]
\frametitle{Types of ...}
\begin{table}
    \bfseries
    \begin{tabular}{|C{.16\textwidth}|C{.16\textwidth}|C{.28\textwidth}|}
        \hline
        hello & \textcolor{blue}{hello} \textcolor{green}{hello} & receptors\\ \hline
        hello & \textcolor{blue}{hello} \textcolor{green}{hello} & \\ \hline
        hello & \textcolor{blue}{hello} \textcolor{green}{hello} & \\ \hline
    \end{tabular}
\end{table}
\end{frame}

\end{document} 

请注意以下变化:

  • \bf已被弃用,不应再使用。

  • 您不应在宏的参数中使用格式化指令,例如\frametitle。如果您想更改字体,请使用\setbeamerfont{frametitle}{series=\bfseries}

  • 嵌套一个table、一个minipage、一个组、一个center环境和一个longtable确实有点过分。默认情况下,表格在 beamer 中居中,并且minipage和 组没有任何用处。此外,您没有使用 的任何特殊功能longtable

  • Beamer 没有浮点数,因此指定浮点说明符毫无意义

  • \centering是一个开关,它不接受参数。

在此处输入图片描述

相关内容