无法在表头中添加符号

无法在表头中添加符号

以下是一张表格:

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

现在我试图将\textbf{foo}(第一列的名称)更改为\neg B 但我收到以下错误:!缺少 $ 插入。$ l.55 }

答案1

正如评论中已经指出的那样,您需要 TeX 的数学模式才能使用\neg宏。即输入$\neg B$而不是仅仅输入\neg B

表格的一个更根本的问题是代码是很多太复杂了。特别是,没有必要将每个单元格都包含在语句中\multicolumn{1}{...}{...}。这样做不仅效率极低,而且会使调试变得比需要的更加繁琐。在下面的代码中,你会发现没有一个 \multicolumn陈述。

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

相关内容