
Construí esta tabla basada en una anterior.Preguntas y respuestas:
Como puede ver, hay un problema con el encabezado.
¿Cómo puedo desactivar el resaltado sólo para los encabezados?
Aquí está el código:
\documentclass{article}
\usepackage{booktabs}
\usepackage{colortbl}
\usepackage{xcolor}
\makeatletter
\newcommand*{\yncellcolor}{}
\def\yncellcolor\ignorespaces{\@ifnextchar{1}{\cellcolor{green!20}}{\@ifnextchar{0}{\cellcolor{red!20}}{}}}
\newcolumntype{C}{>{\yncellcolor}c}
\makeatother
\begin{document}
\begin{table}[htp]
\caption{XOR}
\begin{center}
\begin{tabular}{CCCCCCCCCCCCCCCCCC}
\toprule
$Bit$ & 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 \\
\midrule
$A$ & 0 & 1 & 0 & 1 & 0 & 1 & 0 & 1 \\
$B$ & 1 & 0 & 1 & 0 & 1 & 0 & 1 & 0 \\
$\bigoplus$ & 1 & 1 & 1 & 1 & 1 & 1 & 1 & 1 \\
\bottomrule
\end{tabular}
\end{center}
\label{XOR}
\end{table}
\end{document}
Respuesta1
¿Como esto?
Después de reparar (completar) su MWE... sugiero usar diferentes tipos de columnas para los encabezados de columna definidos por \multicolumn{1}{c}{...}
.
\documentclass{article}
\usepackage[table]{xcolor}
\usepackage{booktabs}
\makeatletter
\newcommand*{\yncellcolor}{}
\def\yncellcolor\ignorespaces{\@ifnextchar{1}{\cellcolor{green!20}}{\@ifnextchar{0}{\cellcolor{red!20}}{}}}
\newcolumntype{C}{>{\yncellcolor}c}
\makeatother
\newcommand\mc[1]{\multicolumn{1}{c}{#1}} % <--- new
\begin{document}
\begin{table}[htp]
\caption{XOR}
\centering
\begin{tabular}{l| *{8}{C}}
\toprule
$Bit$ &\mc{1} &\mc{2} &\mc{3} &\mc{4} &\mc{5} &\mc{6} &\mc{7} &\mc{8} \\ % <--- changed
\midrule
$A$ & 0 & 1 & 0 & 1 & 0 & 1 & 0 & 1 \\
$B$ & 1 & 0 & 1 & 0 & 1 & 0 & 1 & 0 \\
$\bigoplus$ & 1 & 1 & 1 & 1 & 1 & 1 & 1 & 1 \\
\bottomrule
\end{tabular}
\label{XOR}
\end{table}
\end{document}
Nota: el uso de las líneas verticales en la tabla y las reglas de uso booktabs
no funcionan bien juntos. Deberías considerar otra combinación de líneas (por ejemplo, \hlineB{...}
del boldline
paquete):
\documentclass{article}
\usepackage[table]{xcolor}
\usepackage{boldline}
\makeatletter
\newcommand*{\yncellcolor}{}
\def\yncellcolor\ignorespaces{\@ifnextchar{1}{\cellcolor{green!20}}{\@ifnextchar{0}{\cellcolor{red!20}}{}}}
\newcolumntype{C}{>{\yncellcolor}c}
\makeatother
\newcommand\mc[1]{\multicolumn{1}{c}{#1}} % <--- new
\begin{document}
\begin{table}[htp]
\caption{XOR}
\centering
\begin{tabular}{>{\rule[-1ex]{0pt}{4ex}$}l<{$} | *{8}{C}}
\hlineB{2}
\mathrm{Bit} &\mc{1} &\mc{2} &\mc{3} &\mc{4} &\mc{5} &\mc{6} &\mc{7} &\mc{8} \\ % <--- changed
\hlineB{1.5}
A & 0 & 1 & 0 & 1 & 0 & 1 & 0 & 1 \\
B & 1 & 0 & 1 & 0 & 1 & 0 & 1 & 0 \\
\bigoplus & 1 & 1 & 1 & 1 & 1 & 1 & 1 & 1 \\
\hlineB{2}
\end{tabular}
\label{XOR}
\end{table}
\end{document}