0

Using the following code, I can not figure out why the last column text is not displayed when using the code

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

giving the error message

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

but it only could be displayed when using the code

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

MWE:

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

enter image description here

Hany
  • 4,709

1 Answers1

2

The code seems unnecessarily complicate, I'd write the table like this:

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

Please note the following changes:

  • \bf is deprecated and should no longer be used.

  • You should not use formatting instructions in arguments of macros like \frametitle. If you want to change the font, use \setbeamerfont{frametitle}{series=\bfseries}

  • nesting a table, a minipage, a group, a center environment and a longtable is really overkill. Tables are centred by default in beamer, and the minipage and the group don't do anything useful. Also you are not using any special features of the longtable

  • Beamer does not have floats, it makes no sense to specify floating specifier

  • \centering is a switch, it does not take arguments.

enter image description here

  • Thank you very much for your answer. Could you please tell me what was wrong in the code I used. – Hany Oct 05 '18 at 10:43
  • @Hany \centering redefines what \\ means, which also explains why it is only a problem in the lat column. The trick is also using \arraybackslash which reverts the table/array meaning of \\ as the ender of a row\ – daleif Oct 05 '18 at 10:59
  • @samcarter Thank you very much for your explanation. – Hany Oct 05 '18 at 12:31
  • @samcarter Please just one comment. I used m option to vertically align text inside cells; but your fine code does not allow this. Text is still top aligned. – Hany Oct 05 '18 at 14:07
  • @Hany If you look at my code, you'll see that I also use the m column. Also as you can see in my screenshot the text is not top aligned! – samcarter_is_at_topanswers.xyz Oct 05 '18 at 14:09
  • @samcarter I am very sorry. When I applied your code to my original document, in which the table is much more complicated than my MWE, I missed removing one of the old \bf codes, which resulted in that error. Can your code be adjusted to decrease a little bit the horizontal spacing between text and cell boundaries. – Hany Oct 05 '18 at 15:35
  • @Hany Adjusting the space between the content and the lines is a different question. – samcarter_is_at_topanswers.xyz Oct 05 '18 at 19:07