![使用 tabular 和 tabularx 以及 \hline 时放错了 \noalign](https://linux22.com/image/408141/%E4%BD%BF%E7%94%A8%20tabular%20%E5%92%8C%20tabularx%20%E4%BB%A5%E5%8F%8A%20%5Chline%20%E6%97%B6%E6%94%BE%E9%94%99%E4%BA%86%20%5Cnoalign.png)
我在 tabularx 末尾不断收到“Misplaced \noalign”错误。我已经在网上阅读了很多关于它的内容,例如你需要\\
在 之前放置\hline
。我这样做了,但仍然收到此错误。我希望有人能帮助我解决这个问题。
\begin{table}[!ht]
\newcolumntype{a}{>{\columncolor{LightGrey}}X}
\caption{caption}
\begin{tabularx}{\textwidth}{a|c|c|c|c|c|c|c|c|c|c|c|c| }
\rowcolor{White}
&
\rowcolor{Blue}
\textbf{\ref{F:1}} & \textbf{\ref{F:2}} & \textbf{\ref{F:3}} & \textbf{\ref{F:5}} & \textbf{\ref{F:6}} & \textbf{\ref{F:7}} & \textbf{\ref{F:8}} & \textbf{\ref{F:9}} & \textbf{\ref{F:10}} & \textbf{\ref{F:13}} \\ \hline
\textbf{availablity} & \checkmark & o & x & x & x & x & x & x & x & x \\ \hline
\end{tabularx}
\begin{center}
\boldcheckmark = explicitly advertised, \checkmark = available, X = unavailable, O = non-identifiable
\end{center}
\end{table}
答案1
像这样?
\columncolor
用于对列进行着色\rowcolor
只能位于行首,不能位于中间;\rowcolor
超越columncolor
\cellcolor
用于为一个单元格着色,它会覆盖\rowcolor
并column
着色
\documentclass{article}
\usepackage[table, svgnames]{xcolor}
\usepackage{tabularx}
\usepackage{pifont}
\providecommand*{\checkmark}{\ding{51}}
\providecommand*{\boldcheckmark}{\textbf{\checkmark}}
\begin{document}
\begin{table}[!ht]
\setlength\extrarowheight{2pt}
\caption{caption}
\begin{tabularx}{\textwidth}{c | *{10}{>{\centering\arraybackslash}X|} }
\rowcolor{cyan!30}
\cellcolor{white}
& \textbf{\ref{F:1}} & \textbf{\ref{F:2}} & \textbf{\ref{F:3}} & \textbf{\ref{F:5}}
& \textbf{\ref{F:6}} & \textbf{\ref{F:7}} & \textbf{\ref{F:8}} & \textbf{\ref{F:9}} & \textbf{\ref{F:10}}& \textbf{\ref{F:13}} \\ \hline
\cellcolor{LightGrey}{availablity} & \checkmark & o & x & x & x & x & x & x & x & x \\ \hline
\end{tabularx}
\begin{center}
\boldcheckmark = explicitly advertised, \checkmark = available, x = unavailable, o = non-identifiable
\end{center}
\end{table}
\end{document}
答案2
或者像这样?此解决方案假定这两\rowcolor
条指令都应该是真正的\cellcolor
指令。
请注意,我故意省略了所有垂直和水平规则,因为它们除了造成视觉混乱之外什么也没有提供。
\documentclass{article}
\usepackage[table,svgnames]{xcolor}
\usepackage{tabularx,amssymb,bm}
\newcolumntype{a}{>{\columncolor{LightGrey}}X}
\providecommand\boldcheckmark{\bm{\checkmark}}
\usepackage[skip=0.333\baselineskip]{caption} % optional
\begin{document}
\begin{table}[!ht]
\setlength\tabcolsep{5pt} % default: 6pt
\setlength\extrarowheight{2pt} % for a less-cramped "look"
\caption{caption}
\begin{tabularx}{\textwidth}{ a *{10}{c} @{}}
\cellcolor{White} & % <-- was "\rowcolor{White}
\cellcolor{LightBlue} % <-- was "\rowcolor{Blue}"
\ref{F:1} & \ref{F:2} & \ref{F:3} & \ref{F:5} & \ref{F:6} &
\ref{F:7} & \ref{F:8} & \ref{F:9} & \ref{F:10} & \ref{F:13} \\
Availablity & \checkmark & o & x & x & x & x & x & x & x & x \\
\end{tabularx}
\medskip
\boldcheckmark = explicitly advertised, \checkmark = available,
x = unavailable, o = non-identifiable.
\end{table}
\end{document}