我正在尝试用 LaTeX 制作表格。但是,我得到了几个额外的对齐标签错误,我不知道为什么。
我在这里搜索过类似的问题,但我只发现额外的对齐标签错误
这是由 引起的另一个问题%
,我没有使用 。所以,目前我很迷茫。
以下是重现错误的一些最少代码:
\documentclass[a4paper,10pt]{article}
\usepackage[table]{xcolor}
\usepackage[utf8]{inputenc}
\usepackage{tabularx}
\usepackage{array}
%define some nice colors
\definecolor{middleware_green}{RGB}{82, 119, 17}
\definecolor{middleware_white}{RGB}{255, 255, 255}
\definecolor{middleware_light_gray}{RGB}{239, 239, 239}
\definecolor{middleware_dark_gray}{RGB}{153, 153, 153}
%renewing commands for tabularx
\renewcommand{\tabularxcolumn}[1]{>{\small}m{#1}}
%new column type for test tables
\newcolumntype{L}{>{\leavevmode\ignorespaces\raggedleft\arraybackslash\sffamily}X}%
\newcolumntype{C}{>{\leavevmode\ignorespaces\centering\arraybackslash\sffamily}X}%
\newcolumntype{R}{|>{\leavevmode\ignorespaces\color{magenta!70!black}\raggedright\sffamily\bfseries\footnotesize}p{2.5cm}}%
\newcolumntype{H}{|>{\leavevmode\ignorespaces\color{orange!30!black}\centering\arraybackslash\sffamily\footnotesize}X}%
\newcolumntype{J}{|>{\leavevmode\ignorespaces\color{green!30!black}\centering\sffamily\footnotesize}X}%
\newcolumntype{W}{|>{\leavevmode\ignorespaces\color{blue!30!black}\centering\arraybackslash\sffamily\footnotesize}X|}%
\begin{document}
\begin{table}[ph!]
\footnotesize\centering
\rowcolors{2}{middleware_white}{middleware_light_gray}
\begin{tabularx}{0.46\textwidth}{|L|L|L|L|L|}
\hline\rowcolor{middleware_green}
\multicolumn{ 5}{|c|}{\small\textcolor{white}{\textbf{Cloud Types}}} \\ \hline
\rowcolor{middleware_dark_gray}
\multicolumn{1}{|C}{\scriptsize\textcolor{white}{\textbf{Pu\-blic cloud}}} &
\multicolumn{1}{|C}{\scriptsize\centering\textcolor{white}{\textbf{Pri\-va\-te cloud}}} &
\multicolumn{1}{|C}{\scriptsize\centering\textcolor{white}{\textbf{Hy\-brid cloud}}} &
\multicolumn{1}{|C|}{\scriptsize\textcolor{white}{\textbf{Vir\-tu\-al pri\-va\-te cloud}}} &
\multicolumn{1}{|C|}{\scriptsize\textcolor{white}{\textbf{Com\-mu\-ni\-ty cloud}}} & \\ \hline
Definition & Public cloud definition & Private cloud definition & Hybrid cloud defitnion & Virtual Private Cloud definition & Community Cloud definition \\ \hline
Advantages & Public cloud advantages & Private cloud advantages & Hybrid cloud advantages & Virtual Private Cloud advantages & Community Cloud advantages \\ \hline
Disadvantages & Public cloud disadvantages & Private cloud disadvantages & Hybrid cloud disadvantages & Virtual Private Cloud disadvantages & Community Cloud disadvantages \\ \hline
\end{tabularx}
\caption{Cloud Types\label{tab:cloud_types}}
\end{table}
\end{document}
我错过了什么?
答案1
内容tabular
分为六列,但只有五列用宏声明。
就像是:
\begin{tabular}{|L|L|L|L|L|} %five columns
1&2&3&4&5&6 %six columns
\end{tabular}
这是行不通的。
为了解决编译错误,列数应该等于或小于用宏声明的列数。