3

I've got following table which is almost what I wanted to have. But it would be much better if cells with text would be aligned vertical (only vertical) and cells with -- would be aligned vertical & horizontal.

Does anyone has a suggestion on that issue?

Here is my table:

\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}

2 Answers 2

2

In your particular case it's sufficient to override the \raggedright declaration, so

\newcommand{\nodata}{\centering\arraybackslash --}

will do the trick. Sample row:

\rowcolor[gray]{.9}
  Canada, France, Germany &
  Italy, Japan, United Kingdom, United States &
  \nodata &
  \nodata \

enter image description here

1
  • Many thanks egreg! Your approach has the advantage of using less code. Thanks. Commented Feb 14, 2012 at 11:44
4

please use only packages which are part of any TeX-distribution!

\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}

enter image description here

2
  • Thank you Herbert. Worked perfect! What did you mean by "please use only packages which are part of any TeX-distribution!"? Commented Feb 14, 2012 at 11:36
  • The classicthesis-ldpkg package has been dropped in the more recent versions of the classicthesis bundle. Commented Feb 14, 2012 at 11:39

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.