0

This question already has an answer here:

So, here is a table:

\begin{table}[h]
\begin{tabular}{llllllll}
\rowcolor[HTML]{EFEFEF} 
\textbf{foo}            & \textbf{bar}           & \textbf{foobar}        & \textbf{fsj}           & \textbf{jifd}          & \textbf{jifd}          & \textbf{jif}                                                          & \textbf{ifi}                                                          \\ \hline
\multicolumn{1}{|l|}{1} & \multicolumn{1}{l|}{1} & \multicolumn{1}{l|}{1} & \multicolumn{1}{l|}{0} & \multicolumn{1}{l|}{1} & \multicolumn{1}{l|}{1} & \multicolumn{1}{l|}{\cellcolor[HTML]{FFCCC9}{\color[HTML]{3166FF} 1}} & \multicolumn{1}{l|}{\cellcolor[HTML]{FFCCC9}{\color[HTML]{3166FF} 1}} \\ \hline
\multicolumn{1}{|l|}{1} & \multicolumn{1}{l|}{1} & \multicolumn{1}{l|}{0} & \multicolumn{1}{l|}{0} & \multicolumn{1}{l|}{0} & \multicolumn{1}{l|}{1} & \multicolumn{1}{l|}{0}                                                & \multicolumn{1}{l|}{1}                                                \\ \hline
\multicolumn{1}{|l|}{1} & \multicolumn{1}{l|}{0} & \multicolumn{1}{l|}{1} & \multicolumn{1}{l|}{1} & \multicolumn{1}{l|}{1} & \multicolumn{1}{l|}{1} & \multicolumn{1}{l|}{\cellcolor[HTML]{FFCCC9}{\color[HTML]{3166FF} 1}} & \multicolumn{1}{l|}{\cellcolor[HTML]{FFCCC9}{\color[HTML]{3166FF} 1}} \\ \hline
\multicolumn{1}{|l|}{1} & \multicolumn{1}{l|}{0} & \multicolumn{1}{l|}{0} & \multicolumn{1}{l|}{1} & \multicolumn{1}{l|}{1} & \multicolumn{1}{l|}{1} & \multicolumn{1}{l|}{\cellcolor[HTML]{FFCCC9}{\color[HTML]{3166FF} 1}} & \multicolumn{1}{l|}{\cellcolor[HTML]{FFCCC9}{\color[HTML]{3166FF} 1}} \\ \hline
\multicolumn{1}{|l|}{0} & \multicolumn{1}{l|}{1} & \multicolumn{1}{l|}{1} & \multicolumn{1}{l|}{0} & \multicolumn{1}{l|}{1} & \multicolumn{1}{l|}{1} & \multicolumn{1}{l|}{\cellcolor[HTML]{FFCCC9}{\color[HTML]{3166FF} 1}} & \multicolumn{1}{l|}{\cellcolor[HTML]{FFCCC9}{\color[HTML]{3166FF} 1}} \\ \hline
\multicolumn{1}{|l|}{0} & \multicolumn{1}{l|}{1} & \multicolumn{1}{l|}{0} & \multicolumn{1}{l|}{0} & \multicolumn{1}{l|}{0} & \multicolumn{1}{l|}{1} & \multicolumn{1}{l|}{0}                                                & \multicolumn{1}{l|}{0}                                                \\ \hline
\multicolumn{1}{|l|}{0} & \multicolumn{1}{l|}{0} & \multicolumn{1}{l|}{1} & \multicolumn{1}{l|}{1} & \multicolumn{1}{l|}{1} & \multicolumn{1}{l|}{0} & \multicolumn{1}{l|}{0}                                                & \multicolumn{1}{l|}{1}                                                \\ \hline
\multicolumn{1}{|l|}{0} & \multicolumn{1}{l|}{0} & \multicolumn{1}{l|}{0} & \multicolumn{1}{l|}{1} & \multicolumn{1}{l|}{1} & \multicolumn{1}{l|}{0} & \multicolumn{1}{l|}{0}                                                & \multicolumn{1}{l|}{0}                                                \\ \hline
\end{tabular}
\end{table}

Now I am trying to change the \textbf{foo} (name of first column) to \neg B But I get the following error: ! Missing $ inserted. $ l.55 }

marked as duplicate by LaRiFaRi, karlkoeller, Claudio Fiandrino, moewe, Svend Tveskæg Jan 8 '15 at 9:08

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • 2
    Replace \neg B by $\neg B$. And why not \begin{tabular}{|l|l|l|l|l|l|l|l|}? (en.wikibooks.org/wiki/LaTeX/Tables) – Symbol 1 Jan 8 '15 at 7:20
  • 2
    Welcome to TeX.SE. While code snippets are useful in explanations, it is always best to compose a fully compilable MWE that illustrates the problem including the \documentclass and the appropriate packages so that those trying to help don't have to recreate it. – Peter Grill Jan 8 '15 at 7:21
  • @PeterGrill Cool. I will keep that in mind :) – Fraz Jan 8 '15 at 7:27
  • @Symbol Thanks for the reference. I have just got started. BBut thanks for the reference – Fraz Jan 8 '15 at 7:28
  • 5
    Also, I would recommend you have a look at the booktabs package and avoid vertical rules. – Peter Grill Jan 8 '15 at 7:34
2

As has already been pointed out in the comments, you need TeX's math mode for the \neg macro. I.e., input $\neg B$ instead of just \neg B.

A much more fundamental problem with your tabular is that the code is much too complicated. In particular, it is simply not necessary to encase each and every cell in a \multicolumn{1}{...}{...} statement. Not only is doing so grossly inefficient, it also makes debugging far more tedious than needs to be the case. In the code below, you'll find not a single \multicolumn statement.

\documentclass{book}
\usepackage[table]{xcolor}
% define a shortcut macro to change both cell and text color
\newcommand\combinedcolor{\cellcolor[HTML]{FFCCC9}\color[HTML]{3166FF}}
\begin{document}
\begin{table}[h]
\begin{tabular}{|l|l|l|l|l|l|l|l|}
\hline
\rowcolor[HTML]{EFEFEF}
$\neg B$ & \textbf{bar} & \textbf{foobar} & \textbf{fsj}  & 
\textbf{jifd} & \textbf{jifd} & \textbf{jif} & \textbf{ifi} \\ \hline
1 & 1 & 1 & 0 & 1 & 1 & \combinedcolor 1 & \combinedcolor 1 \\ \hline
1 & 1 & 0 & 0 & 0 & 1 & 0 & 1 \\ \hline
1 & 0 & 1 & 1 & 1 & 1 & \combinedcolor 1 & \combinedcolor 1 \\ \hline
1 & 0 & 0 & 1 & 1 & 1 & \combinedcolor 1 & \combinedcolor 1 \\ \hline
0 & 1 & 1 & 0 & 1 & 1 & \combinedcolor 1 & \combinedcolor 1 \\ \hline
0 & 1 & 0 & 0 & 0 & 1 & 0 & 0 \\ \hline
0 & 0 & 1 & 1 & 1 & 0 & 0 & 1 \\ \hline
0 & 0 & 0 & 1 & 1 & 0 & 0 & 0 \\ \hline
\end{tabular}
\end{table}
\end{document}

Not the answer you're looking for? Browse other questions tagged or ask your own question.