我得到了下面的表格,这几乎就是我想要的。但如果包含文本的单元格垂直对齐(仅垂直),并且包含文本的单元格--
垂直和水平对齐,效果会更好。
有人对这个问题有什么建议吗?
这是我的表格:
\documentclass[10pt,a4paper]{scrreprt}
\usepackage{classicthesis-ldpkg}
\usepackage{multicol}
\usepackage{multirow}
\usepackage{rotating}
\usepackage[table]{xcolor}
\usepackage{booktabs}
\usepackage{lscape}
\newcolumntype{R}[1]{>{\raggedright\arraybackslash}p{#1}}
\begin{document}
\begin{landscape}
\begin{tabular}{R{4cm}R{4cm}R{4cm}R{4cm}} %<--- damit geht es jetzt auch ;)
\toprule
\multicolumn{1}{c}{\textbf{Cluster 1}} & \multicolumn{1}{c}{\textbf{Cluster 2}} & \multicolumn{1}{c}{\textbf{Cluster 3}} & \multicolumn{1}{c}{\textbf{Cluster 4}} \\
\midrule
\rowcolor[gray]{.9} Canada, France, Germany & Italy, Japan, United Kingdom, United States & -- & --\\
Austria, Belgium, Netherlands, Switzerland & -- & Luxembourg & --\\
\rowcolor[gray]{.9} Finland, Iceland, Norway, Sweden & Denmark, Ireland & -- & --\\
-- & Estonia, Hungary & Czech Republic, Slovenia & Poland, Slovak Republic \\
\rowcolor[gray]{.9} Greece, Portugal, Spain & -- & -- & -- \\
New Zealand & -- & Australia, Korea, Turkey & Israel \\
\bottomrule
\end{tabular}
\end{landscape}
\end{document}
答案1
在你的特定情况下,覆盖\raggedright
声明就足够了,所以
\newcommand{\nodata}{\centering\arraybackslash --}
就可以了。示例行:
\rowcolor[gray]{.9}
Canada, France, Germany &
Italy, Japan, United Kingdom, United States &
\nodata &
\nodata \
答案2
请仅使用属于任何 TeX 发行版的软件包!
\documentclass[10pt,a4paper]{scrreprt}
\usepackage[table]{xcolor}
\usepackage{booktabs}
\usepackage{lscape}
\newcolumntype{R}[1]{>{\raggedright\arraybackslash}m{#1}}
\newcommand\Ctr[1]{\multicolumn{1}{>{\cellcolor[gray]{#1}}c}{--}}
\begin{document}
\begin{landscape}
\renewcommand\arraystretch{1.3}
\begin{tabular}{R{4cm}R{4cm}R{4cm}R{4cm}}\toprule
\multicolumn{1}{c}{\textbf{Cluster 1}} & \multicolumn{1}{c}{\textbf{Cluster 2}} & \multicolumn{1}{c}{\textbf{Cluster 3}} & \multicolumn{1}{c}{\textbf{Cluster 4}} \\\midrule
\rowcolor[gray]{.9} Canada, France, Germany & Italy, Japan, United Kingdom, United States
& \Ctr{0.9} & \Ctr{0.9} \\
Austria, Belgium, Netherlands, Switzerland & \Ctr{1} & Luxembourg & \Ctr{1} \\
\rowcolor[gray]{.9} Finland, Iceland, Norway, Sweden & Denmark, Ireland & \Ctr{0.9} & \Ctr{0.9}\\
\Ctr{1} & Estonia, Hungary & Czech Republic, Slovenia & Poland, Slovak Republic \\
\rowcolor[gray]{.9} Greece, Portugal, Spain & \Ctr{0.9} & \Ctr{0.9} & \Ctr{0.9} \\
New Zealand & \Ctr{1} & Australia, Korea, Turkey & Israel \\ \bottomrule
\end{tabular}
\end{landscape}
\end{document}