我的文档中有这张表格,正如您所看到的,第二行的数字没有居中,我尝试使用以前提出的问题中的一些解决方案,但没有一个可以解决这个问题。
该表的 LaTeX 代码为:
\documentclass[xcolor=table]{beamer}
\usepackage{array}
\newcolumntype{P}[1]{>{\parbox{20em}}m{#1}}
\begin{document}
\begin{table}[]
\centering
\begin{tabular}{cccccc|P{0.02cm}|
>{\columncolor[HTML]{FD6864}}P{0.02cm} |
>{\columncolor[HTML]{FD6864}}P{0.02cm} |
>{\columncolor[HTML]{FD6864}}P{0.02cm} |
>{\columncolor[HTML]{FD6864}}P{0.02cm} |
>{\columncolor[HTML]{FD6864}}P{0.02cm} |
>{\columncolor[HTML]{FD6864}}P{0.02cm} |
>{\columncolor[HTML]{FD6864}}P{0.02cm} |
>{\columncolor[HTML]{FD6864}}P{0.02cm} |
>{\columncolor[HTML]{FD6864}}P{0.02cm} |
>{\columncolor[HTML]{FD6864}}P{0.02cm} |
>{\columncolor[HTML]{FD6864}}P{0.02cm} |
>{\columncolor[HTML]{FD6864}}P{0.02cm} |
>{\columncolor[HTML]{FD6864}}P{0.02cm} |
>{\columncolor[HTML]{FD6864}}P{0.02cm} |
>{\columncolor[HTML]{FD6864}}P{0.02cm} |
>{\columncolor[HTML]{FD6864}}P{0.02cm} |
>{\columncolor[HTML]{FD6864}}P{0.02cm} |
>{\columncolor[HTML]{FD6864}}P{0.02cm} |
>{\columncolor[HTML]{FD6864}}P{0.02cm} |
>{\columncolor[HTML]{FD6864}}P{0.02cm} |
>{\columncolor[HTML]{FD6864}}P{0.02cm} |
>{\columncolor[HTML]{FD6864}}P{0.02cm} |
>{\columncolor[HTML]{FD6864}}P{0.02cm} |
>{\columncolor[HTML]{FD6864}}P{0.02cm} |
>{\columncolor[HTML]{FD6864}}P{0.02cm} |
>{\columncolor[HTML]{FD6864}}P{0.02cm} |
>{\columncolor[HTML]{FD6864}}P{0.02cm} |}
\cline{7-34}
\multicolumn{1}{l}{} & \multicolumn{1}{l}{} & \multicolumn{1}{l}{} & \multicolumn{1}{l}{} & \multicolumn{1}{l}{} & \multicolumn{1}{l|}{} & \multicolumn{28}{c|}{\cellcolor[HTML]{C0C0C0}\textbf{Something}} \\ \hline
\multicolumn{1}{|l|}{\cellcolor[HTML]{C0C0C0}One} & \multicolumn{1}{l|}{\cellcolor[HTML]{C0C0C0}Two} & \multicolumn{1}{l|}{\cellcolor[HTML]{C0C0C0}Three} & \multicolumn{1}{l|}{\cellcolor[HTML]{C0C0C0}Four} & \multicolumn{1}{l|}{\cellcolor[HTML]{C0C0C0}Five} & \multicolumn{1}{l|}{\cellcolor[HTML]{C0C0C0}Six} & \cellcolor[HTML]{C0C0C0}1 & \cellcolor[HTML]{C0C0C0}2 & \cellcolor[HTML]{C0C0C0}3 & \cellcolor[HTML]{C0C0C0}4 & \cellcolor[HTML]{C0C0C0}5 & \cellcolor[HTML]{C0C0C0}6 & \cellcolor[HTML]{C0C0C0}7 & \cellcolor[HTML]{C0C0C0}8 & \cellcolor[HTML]{C0C0C0}9 & \cellcolor[HTML]{C0C0C0}10 & \cellcolor[HTML]{C0C0C0}11 & \cellcolor[HTML]{C0C0C0}12 & \cellcolor[HTML]{C0C0C0}13 & \cellcolor[HTML]{C0C0C0}14 & \cellcolor[HTML]{C0C0C0}15 & \cellcolor[HTML]{C0C0C0}16 & \cellcolor[HTML]{C0C0C0}17 & \cellcolor[HTML]{C0C0C0}18 & \cellcolor[HTML]{C0C0C0}19 & \cellcolor[HTML]{C0C0C0}20 & \cellcolor[HTML]{C0C0C0}21 & \cellcolor[HTML]{C0C0C0}22 & \cellcolor[HTML]{C0C0C0}23 & \cellcolor[HTML]{C0C0C0}24 & \cellcolor[HTML]{C0C0C0}25 & \cellcolor[HTML]{C0C0C0}26 & \cellcolor[HTML]{C0C0C0}27 & \cellcolor[HTML]{C0C0C0}28 \\ \hline
\multicolumn{1}{|c|}{I} & \multicolumn{1}{c|}{-----} & \multicolumn{1}{c|}{5} & \multicolumn{1}{c|}{43} & \multicolumn{1}{c|}{3} & 0 & \cellcolor[HTML]{32CB00} & & & & & & & & & & & & & & & \cellcolor[HTML]{32CB00} & & & & & \cellcolor[HTML]{32CB00} & \cellcolor[HTML]{32CB00} & & & & & & \cellcolor[HTML]{32CB00} \\ \hline
\multicolumn{1}{|c|}{II} & \multicolumn{1}{c|}{0} & \multicolumn{1}{c|}{4} & \multicolumn{1}{c|}{5} & \multicolumn{1}{c|}{2} & 3 & \cellcolor[HTML]{32CB00} & \cellcolor[HTML]{32CB00} & \cellcolor[HTML]{32CB00} & \cellcolor[HTML]{32CB00} & \cellcolor[HTML]{32CB00} & \cellcolor[HTML]{32CB00} & & \cellcolor[HTML]{32CB00} & \cellcolor[HTML]{32CB00} & \cellcolor[HTML]{32CB00} & & \cellcolor[HTML]{32CB00} & \cellcolor[HTML]{32CB00} & \cellcolor[HTML]{32CB00} & \cellcolor[HTML]{32CB00} & \cellcolor[HTML]{32CB00} & \cellcolor[HTML]{32CB00} & \cellcolor[HTML]{32CB00} & \cellcolor[HTML]{32CB00} & \cellcolor[HTML]{32CB00} & \cellcolor[HTML]{32CB00} & \cellcolor[HTML]{32CB00} & & \cellcolor[HTML]{32CB00} & \cellcolor[HTML]{32CB00} & \cellcolor[HTML]{32CB00} & \cellcolor[HTML]{32CB00} & \\ \hline
\multicolumn{1}{|c|}{III} & \multicolumn{1}{c|}{0} & \multicolumn{1}{c|}{0} & \multicolumn{1}{c|}{0} & \multicolumn{1}{c|}{0} & 0 & \cellcolor[HTML]{FD6864} & & & & & & & & & & & & & & & \cellcolor[HTML]{FD6864} & & & & & \cellcolor[HTML]{FD6864} & \cellcolor[HTML]{FD6864} & & & & & & \\ \hline
\multicolumn{1}{|c|}{IV} & \multicolumn{1}{c|}{0} & \multicolumn{1}{c|}{0} & \multicolumn{1}{c|}{0} & \multicolumn{1}{c|}{0} & 0 & \cellcolor[HTML]{FD6864} & & & & & & & & & & & & & & & \cellcolor[HTML]{FD6864} & & & & & \cellcolor[HTML]{FD6864} & \cellcolor[HTML]{FD6864} & & & & & & \\ \hline
\multicolumn{1}{|c|}{V} & \multicolumn{1}{c|}{0} & \multicolumn{1}{c|}{0} & \multicolumn{1}{c|}{0} & \multicolumn{1}{c|}{0} & 0 & \cellcolor[HTML]{FD6864} & & & & & & & & & & & & & & & \cellcolor[HTML]{FD6864} & & & & & \cellcolor[HTML]{FD6864} & \cellcolor[HTML]{FD6864} & & & & & & \\ \hline
\end{tabular}
\end{table}
\end{document}
有人有解决方案吗?
答案1
由于列太窄,数字未居中。下面我使用了collcell
收集单元格条目并将它们放在零宽度框内。这样它们看起来就位于列的中心0.2mm
。
\documentclass{article}
\usepackage[
margin=1in,
landscape
]{geometry}% Just for this example
\usepackage[table]{xcolor}
\usepackage{collcell}
\newcommand{\centercell}{\makebox[0pt]}
\newcolumntype{P}[1]{>{\collectcell\centercell}m{#1}<{\endcollectcell}}
\begin{document}
\begin{tabular}{ *{6}{c} | *{28}{>{\columncolor[HTML]{FD6864}}P{0.2mm} |} }
\cline{7-34}
\multicolumn{1}{l}{} & \multicolumn{1}{l}{} & \multicolumn{1}{l}{} &
\multicolumn{1}{l}{} & \multicolumn{1}{l}{} & \multicolumn{1}{l|}{} &
\multicolumn{28}{c|}{\cellcolor[HTML]{C0C0C0}\textbf{Something}} \\
\hline
\multicolumn{1}{|l|}{\cellcolor[HTML]{C0C0C0}One} &
\multicolumn{1}{l|}{\cellcolor[HTML]{C0C0C0}Two} &
\multicolumn{1}{l|}{\cellcolor[HTML]{C0C0C0}Three} &
\multicolumn{1}{l|}{\cellcolor[HTML]{C0C0C0}Four} &
\multicolumn{1}{l|}{\cellcolor[HTML]{C0C0C0}Five} &
\multicolumn{1}{l|}{\cellcolor[HTML]{C0C0C0}Six} &
\cellcolor[HTML]{C0C0C0}1 & \cellcolor[HTML]{C0C0C0}2 & \cellcolor[HTML]{C0C0C0}3 &
\cellcolor[HTML]{C0C0C0}4 & \cellcolor[HTML]{C0C0C0}5 & \cellcolor[HTML]{C0C0C0}6 &
\cellcolor[HTML]{C0C0C0}7 & \cellcolor[HTML]{C0C0C0}8 & \cellcolor[HTML]{C0C0C0}9 &
\cellcolor[HTML]{C0C0C0}10 & \cellcolor[HTML]{C0C0C0}11 & \cellcolor[HTML]{C0C0C0}12 &
\cellcolor[HTML]{C0C0C0}13 & \cellcolor[HTML]{C0C0C0}14 & \cellcolor[HTML]{C0C0C0}15 &
\cellcolor[HTML]{C0C0C0}16 & \cellcolor[HTML]{C0C0C0}17 & \cellcolor[HTML]{C0C0C0}18 &
\cellcolor[HTML]{C0C0C0}19 & \cellcolor[HTML]{C0C0C0}20 & \cellcolor[HTML]{C0C0C0}21 &
\cellcolor[HTML]{C0C0C0}22 & \cellcolor[HTML]{C0C0C0}23 & \cellcolor[HTML]{C0C0C0}24 &
\cellcolor[HTML]{C0C0C0}25 & \cellcolor[HTML]{C0C0C0}26 & \cellcolor[HTML]{C0C0C0}27 &
\cellcolor[HTML]{C0C0C0}28 \\
\hline
\multicolumn{1}{|c|}{I} & \multicolumn{1}{c|}{-----} & \multicolumn{1}{c|}{5} &
\multicolumn{1}{c|}{43} & \multicolumn{1}{c|}{3} & 0 & \cellcolor[HTML]{32CB00} &
& & & & & & & & & & & & & & \cellcolor[HTML]{32CB00} & & & & & \cellcolor[HTML]{32CB00} &
\cellcolor[HTML]{32CB00} & & & & & & \cellcolor[HTML]{32CB00} \\
\hline
\multicolumn{1}{|c|}{II} & \multicolumn{1}{c|}{0} & \multicolumn{1}{c|}{4} &
\multicolumn{1}{c|}{5} & \multicolumn{1}{c|}{2} & 3 & \cellcolor[HTML]{32CB00} &
\cellcolor[HTML]{32CB00} & \cellcolor[HTML]{32CB00} & \cellcolor[HTML]{32CB00} &
\cellcolor[HTML]{32CB00} & \cellcolor[HTML]{32CB00} & & \cellcolor[HTML]{32CB00} &
\cellcolor[HTML]{32CB00} & \cellcolor[HTML]{32CB00} & & \cellcolor[HTML]{32CB00} &
\cellcolor[HTML]{32CB00} & \cellcolor[HTML]{32CB00} & \cellcolor[HTML]{32CB00} &
\cellcolor[HTML]{32CB00} & \cellcolor[HTML]{32CB00} & \cellcolor[HTML]{32CB00} &
\cellcolor[HTML]{32CB00} & \cellcolor[HTML]{32CB00} & \cellcolor[HTML]{32CB00} &
\cellcolor[HTML]{32CB00} & & \cellcolor[HTML]{32CB00} & \cellcolor[HTML]{32CB00} &
\cellcolor[HTML]{32CB00} & \cellcolor[HTML]{32CB00} & \\
\hline
\multicolumn{1}{|c|}{III} & \multicolumn{1}{c|}{0} & \multicolumn{1}{c|}{0} &
\multicolumn{1}{c|}{0} & \multicolumn{1}{c|}{0} & 0 & \cellcolor[HTML]{FD6864} &
& & & & & & & & & & & & & & \cellcolor[HTML]{FD6864} & & & & & \cellcolor[HTML]{FD6864} &
\cellcolor[HTML]{FD6864} & & & & & & \\
\hline
\multicolumn{1}{|c|}{IV} & \multicolumn{1}{c|}{0} & \multicolumn{1}{c|}{0} &
\multicolumn{1}{c|}{0} & \multicolumn{1}{c|}{0} & 0 & \cellcolor[HTML]{FD6864} &
& & & & & & & & & & & & & & \cellcolor[HTML]{FD6864} & & & & & \cellcolor[HTML]{FD6864} &
\cellcolor[HTML]{FD6864} & & & & & & \\
\hline
\multicolumn{1}{|c|}{V} & \multicolumn{1}{c|}{0} & \multicolumn{1}{c|}{0} &
\multicolumn{1}{c|}{0} & \multicolumn{1}{c|}{0} & 0 & \cellcolor[HTML]{FD6864} &
& & & & & & & & & & & & & & \cellcolor[HTML]{FD6864} & & & & & \cellcolor[HTML]{FD6864} &
\cellcolor[HTML]{FD6864} & & & & & & \\
\hline
\end{tabular}
\end{document}
请注意,使用相同规范定义多个列的代码简化:*{<num>}{<col spec>}
。它不仅简化了输入,而且使其更易于维护。