我正在尝试用 LaTeX 制作一个表格,几乎成功了。表格如下:
我的问题是:为什么“Gennaio”、“Febbraio”和“Maggio”的第四列宽度与其他列不一样?我需要在代码中修改什么来解决这个问题?
代码如下:
\begin{table}[h]
\begin{tabular}{cllllllllllllllllllll}
\multicolumn{1}{c}{} & \multicolumn{4}{c}{GENNAIO} & \multicolumn{4}{c}{FEBBRAIO} & \multicolumn{4}{c}{MARZO} & \multicolumn{4}{c}{APRILE} & \multicolumn{4}{c}{MAGGIO} \\ \hline
\multicolumn{1}{|c|}{\begin{tabular}[c]{@{}c@{}}Collezione\\ Dati\end{tabular}} & \multicolumn{1}{l|}{\cellcolor[HTML]{9B9B9B}} & \multicolumn{1}{l|}{\cellcolor[HTML]{9B9B9B}} & \multicolumn{1}{l|}{\cellcolor[HTML]{9B9B9B}} & \multicolumn{1}{l|}{\cellcolor[HTML]{9B9B9B}} & \multicolumn{1}{l|}{\cellcolor[HTML]{9B9B9B}} & \multicolumn{1}{l|}{\cellcolor[HTML]{9B9B9B}} & \multicolumn{1}{l|}{\cellcolor[HTML]{9B9B9B}} & \multicolumn{1}{l|}{\cellcolor[HTML]{9B9B9B}} & \multicolumn{1}{l|}{\cellcolor[HTML]{9B9B9B}} & \multicolumn{1}{l|}{\cellcolor[HTML]{9B9B9B}} & \multicolumn{1}{l|}{} & \multicolumn{1}{l|}{} & \multicolumn{4}{l|}{} & \multicolumn{4}{l|}{} \\ \hline
\multicolumn{1}{|c|}{\begin{tabular}[c]{@{}c@{}}Elaborazione\\ Dati\end{tabular}} & \multicolumn{4}{l|}{} & \multicolumn{4}{l|}{} & \multicolumn{1}{l|}{} & \multicolumn{1}{l|}{} & \multicolumn{1}{l|}{\cellcolor[HTML]{9B9B9B}} & \multicolumn{1}{l|}{\cellcolor[HTML]{9B9B9B}} & \multicolumn{1}{l|}{\cellcolor[HTML]{9B9B9B}} & \multicolumn{1}{l|}{\cellcolor[HTML]{9B9B9B}} & \multicolumn{1}{l|}{\cellcolor[HTML]{9B9B9B}} & \multicolumn{1}{l|}{\cellcolor[HTML]{9B9B9B}} & \multicolumn{4}{l|}{} \\ \hline
\multicolumn{1}{|c|}{\begin{tabular}[c]{@{}c@{}}Report\\ Dati\end{tabular}} & \multicolumn{4}{l|}{} & \multicolumn{4}{l|}{} & \multicolumn{4}{l|}{} & \multicolumn{4}{l|}{} & \multicolumn{1}{l|}{\cellcolor[HTML]{9B9B9B}} & \multicolumn{1}{l|}{\cellcolor[HTML]{9B9B9B}} & \multicolumn{1}{l|}{\cellcolor[HTML]{9B9B9B}} & \multicolumn{1}{l|}{\cellcolor[HTML]{9B9B9B}} \\ \hline
\end{tabular}
\end{table}
感谢所有有耐心帮助我的人!R.
答案1
您可以使用该tabularx
包。下面是使用该包的代码makecell
,以便对列和行标题进行通用格式设置,并允许在单元格内换行:
\documentclass[a4paper]{article}
\usepackage[nomarginpar, showframe]{geometry}
\usepackage{setspace}
\usepackage[HTML]{xcolor}
\usepackage{array, tabularx, makecell, colortbl}
\renewcommand\theadfont{\sffamily\bfseries}
\renewcommand\theadset{\setstretch{1.333}}
\newcommand\multicolthead[2]{\multicolumn{#1}{c}{\thead{#2}}}
\begin{document}
\noindent
\begin{table}[h!]
\begin{tabularx}{\textwidth}{|l|*{20}{>{\arraybackslash}X|}}
\multicolumn{1}{c}{}& \multicolthead{4}{GENNAIO}& \multicolthead{4}{FEBBRAIO} & \multicolthead{4}{MARZO} & \multicolthead{4}{APRILE} & \multicolthead{4}{MAGGIO} \\
\hline
\thead{Collezione\\ Dati} & \cellcolor[HTML]{9B9B9B}& \cellcolor[HTML]{9B9B9B} & \cellcolor[HTML]{9B9B9B} & \cellcolor[HTML]{9B9B9B} & \cellcolor[HTML]{9B9B9B} & \cellcolor[HTML]{9B9B9B} & \cellcolor[HTML]{9B9B9B} & \cellcolor[HTML]{9B9B9B} & \cellcolor[HTML]{9B9B9B} &\cellcolor[HTML]{9B9B9B} & & & \multicolumn{4}{l|}{} & \multicolumn{4}{l|}{} \\
\hline
\thead{Elaborazione\\ Dati} & \multicolumn{4}{l|}{} & \multicolumn{4}{l|}{} & & & \cellcolor[HTML]{9B9B9B} & \cellcolor[HTML]{9B9B9B} & \cellcolor[HTML]{9B9B9B} & \cellcolor[HTML]{9B9B9B} & \cellcolor[HTML]{9B9B9B} & \cellcolor[HTML]{9B9B9B} & \multicolumn{4}{l|}{} \\ \hline
\thead{Report\\ Dati} & \multicolumn{4}{l|}{} & \multicolumn{4}{l|}{} & \multicolumn{4}{l|}{} & \multicolumn{4}{l|}{} & \cellcolor[HTML]{9B9B9B} & \cellcolor[HTML]{9B9B9B} & \cellcolor[HTML]{9B9B9B} & \cellcolor[HTML]{9B9B9B} \\
\hline
\end{tabularx}
\end{table}
\end{document}
答案2
我回到这个帖子来询问一些真正相关的问题。
我需要编译以下代码,表示一个表格,与您制作的表格非常相似。但我认为最后一列有些问题。
\begin{table}[h!]
\begin{tabularx}{\textwidth}{|l|*{20}{>{\arraybackslash}X|}}
\multicolumn{1}{c}{}& \multicolthead{3}{\color{RoyalBlue}\textbf{I}}& \multicolthead{3}{\color{RoyalBlue}\textbf{II}} & \multicolthead{3}{\color{RoyalBlue}\textbf{III}} & \multicolthead{3}{\color{RoyalBlue}\textbf{IV}} & \multicolthead{3}{\color{RoyalBlue}\textbf{V}} & \multicolthead{3}{\color{RoyalBlue}\textbf{VI}} \\
\hline
\thead{\color{RoyalBlue}One\\\color{RoyalBlue} Time} & \cellcolor[HTML]{D3D3D3} & \cellcolor[HTML]{D3D3D3} & & \multicolumn{3}{l|}{} & \multicolumn{3}{l|}{} & \multicolumn{3}{l|}{} & \multicolumn{3}{l|}{} & \multicolumn{3}{l|}{} \\
\hline
\thead{\color{RoyalBlue}Two\\\color{RoyalBlue} Times} & & & \cellcolor[HTML]{D3D3D3} & \cellcolor[HTML]{D3D3D3} & & & \multicolumn{3}{l|}{} & \multicolumn{3}{l|}{} & \multicolumn{3}{l|}{} & \multicolumn{3}{l|}{} & \\
\hline
\thead{\color{RoyalBlue}Three\\\color{RoyalBlue}Times} & \multicolumn{3}{l|}{} & & \cellcolor[HTML]{D3D3D3} & \cellcolor[HTML]{D3D3D3} & \cellcolor[HTML]{D3D3D3} & \cellcolor[HTML]{D3D3D3} & \cellcolor[HTML]{D3D3D3} & \cellcolor[HTML]{D3D3D3} & \cellcolor[HTML]{D3D3D3} & \cellcolor[HTML]{D3D3D3} & \cellcolor[HTML]{D3D3D3} & & & \multicolumn{3}{l|}{} \\
\hline
\thead{\color{RoyalBlue}Four\\\color{RoyalBlue} \& Times} & \multicolumn{3}{l|}{} & \multicolumn{3}{l|}{} & \multicolumn{3}{l|}{} & \multicolumn{3}{l|}{} & & \cellcolor[HTML]{D3D3D3} & \cellcolor[HTML]{D3D3D3} & \cellcolor[HTML]{D3D3D3} & & \\
\hline
\end{tabularx}
\end{table}
输出结果如下:
谢谢帮助!R.