1

still working on that table. Here's my new question reguarding the table borders:

It appears, that i do something wrong setting boarders. Here is my code, and a screenshot:

\documentclass{article}
\usepackage{multirow} % Used for the vertical cells
\usepackage{rotating} % Used for the vertical cells

\usepackage{xcolor} % Used for cell-colors
\usepackage{colortbl} % Used for cell-colors

\usepackage[a4paper]{geometry}% Used to set the pdf margins manually
\newgeometry{left=2cm,bottom=0.1cm}

\definecolor{grey}{HTML}{F2F2F2} % Define grey for the cells
\definecolor{red}{HTML}{FF0000} % Define red for testing

\begin{document}
\scriptsize % Use a small font size

\begin{tabular}{|p{0.6cm}|p{0.6cm}|p{0.6cm}|p{0.6cm}|p{0.6cm}|p{0.6cm}|p{0.6cm}|p{0.6cm}|p{0.6cm}|p{0.6cm}|p{0.6cm}|p{0.6cm}|p{0.6cm}|p{0.6cm}|p{0.6cm}|p{0.6cm}|p{0,6cm}|}

\cline{10-17}

\multicolumn{9}{|c|}{} & \multicolumn{2}{p{\dimexpr (0.6cm)*2+2\arrayrulewidth+2\tabcolsep\relax}|}{\cellcolor{grey}Work to retired ratio} & \multicolumn{4}{p{\dimexpr (0.6cm)*4+1\arrayrulewidth+2\tabcolsep\relax}|}{Health care sizing (per thousand)} & \multicolumn{2}{p{\dimexpr (0.6cm)*2+1\arrayrulewidth+2\tabcolsep\relax}|}{\cellcolor{grey}Inverse dependency ratio}\\\cline{3-9}

\multicolumn{2}{|c|}{} & \multicolumn{4}{c|}{\cellcolor{grey}Population (mio.)} & \multicolumn{3}{c}{Workforce (1000)}  & \multicolumn{2}{|c|}{\cellcolor{grey}} & \multicolumn{2}{l|}{Physicians by} & \multicolumn{2}{l}{Nurses by} & \multicolumn{2}{|l|}{\cellcolor{grey}Old agers by}\\\hline

\multicolumn{2}{|c|}{} & \begin{sideways}\cellcolor{grey}\parbox{4cm}{Overall}\end{sideways} & \begin{sideways}\cellcolor{grey}\parbox{4cm}{Young age}\end{sideways} & \begin{sideways}\cellcolor{grey}\parbox{4cm}{Working age}\end{sideways} & \begin{sideways}\cellcolor{grey}\parbox{4cm}{Old age}\end{sideways} & \begin{sideways}\parbox{4cm}{Overall}\end{sideways} & \begin{sideways}\parbox{4cm}{Physicians (Proj: 2025)}\end{sideways} & \begin{sideways}\parbox{4cm}{Nurses (Proj: 2030)}\end{sideways} & \begin{sideways}\parbox{4cm}{\cellcolor{grey}Working age by Old age}\end{sideways} & \begin{sideways}\parbox{4cm}{\cellcolor{grey}Work force by Old age}\end{sideways} & \begin{sideways}\parbox{4cm}{Workforce}\end{sideways} & \begin{sideways}\parbox{4cm}{Working age}\end{sideways} & \begin{sideways}\parbox{4cm}{Workforce}\end{sideways} & \begin{sideways}\parbox{4cm}{Working age}\end{sideways} & \begin{sideways}\parbox{4cm}{\cellcolor{grey}1 physicians}\end{sideways} & \begin{sideways}\parbox{4cm}{\cellcolor{grey}1 nurse}\end{sideways}\\\hline

\multicolumn{2}{|l}{USA} & \multicolumn{4}{l}{\cellcolor{grey}} & \multicolumn{3}{l}{} & \multicolumn{2}{l}{\cellcolor{grey}} & \multicolumn{4}{l}{} & \multicolumn{2}{l|}{\cellcolor{grey}}\\\hline

1990/1 & & 248,6 & 71,3 & 146,1 & 31,2 & 127.500 & 615,4 & 1491,6 & 4,68 & 4,09 & 4,83 & 4,21 & 11,70 & 10,21 & 50,7 & 20,9\\\hline

1 & 2 & 3 \\\hline

\end{tabular}

\end{document}

enter image description here

On 1 the Top border of Population is not visible although i did used \\\cline{3-9}\cline{12-17} on that line.

In 2 both borders are pushed a bit to the right for no reason i can see.

And in 3 again the top borders are not visible despite using \cline{10-17} on that line. What did i do wrong?

Thanks!

4

As documented in the colortbl documentation you can not use \cline with colortbl as \cline rules take up no vertical space so are over-printed by the coloured panels. You can use \hhline from the hhline package, which has a different syntax.

As mentioned last time the vertical rules are at the right edge of the column so use

\multicolumn{2}{c|}{..}&
\multicolumn{2}{c|}{..}&

not

\multicolumn{2}{|c|}{..}&
\multicolumn{2}{|c|}{..}&

Otherwise you get duplicated, mis-aligned vertical rules. Only the first cell in a row should have a rule on the left.

3 is \cline again.

Also rotating package is useful for its sidewaystable environment but for rotating text it just really keeps sideways for compatibility with the LaTeX2.09 package from last century, it uses the graphicx package and you can simply use that and \rotatebox{90}{..} directly.

You also had the calculation of the spanning width incorrect. If you span 4 columns, you have to account for 3 (= 4-1) missing rules and the space wither side of them =6\tabcolsep (6=2*(4-1))

enter image description here

\documentclass{article}
\usepackage{multirow} % Used for the vertical cells
\usepackage{graphicx} % Used for the vertical cells
\usepackage{hhline}
\usepackage{xcolor} % Used for cell-colors
\usepackage{colortbl} % Used for cell-colors

\usepackage[a4paper]{geometry}% Used to set the pdf margins manually
\newgeometry{left=2cm,bottom=0.1cm}

\definecolor{grey}{HTML}{F2F2F2} % Define grey for the cells
\definecolor{red}{HTML}{FF0000} % Define red for testing

\begin{document}
\scriptsize % Use a small font size

\begin{tabular}{|*{17}{p{0.6cm}|}}

\hhline{*9{~}*8-}

\multicolumn{9}{|c|}{}&
\multicolumn{2}{p{\dimexpr (0.6cm)*2+1\arrayrulewidth+2\tabcolsep\relax}|}{\cellcolor{grey}\centering Work to retired ratio}&
\multicolumn{4}{p{\dimexpr (0.6cm)*4+3\arrayrulewidth+6\tabcolsep\relax}|}{\centering Health care sizing\\ (per thousand)}&
\multicolumn{2}{p{\dimexpr (0.6cm)*2+1\arrayrulewidth+2\tabcolsep\relax}|}{\cellcolor{grey}\centering Inverse dependency ratio}\\
\hhline{~~------->{\arrayrulecolor{grey}}-->{\arrayrulecolor{black}}---->{\arrayrulecolor{grey}}-->{\arrayrulecolor{black}}}

\multicolumn{2}{|c|}{}&
 \multicolumn{4}{c|}{\cellcolor{grey}Population (mio.)}&
 \multicolumn{3}{c|}{Workforce (1000)}&
 \multicolumn{2}{c|}{\cellcolor{grey}}&
 \multicolumn{2}{l|}{Physicians by}&
 \multicolumn{2}{l|}{Nurses by}&
 \multicolumn{2}{l|}{\cellcolor{grey}Old agers by}\\
\hline
\multicolumn{2}{|c|}{}&
 \rotatebox{90}{\cellcolor{grey}Overall}&
 \rotatebox{90}{\cellcolor{grey}Young age}&
 \rotatebox{90}{\cellcolor{grey}Working age}&
 \rotatebox{90}{\cellcolor{grey}Old age}&
 \rotatebox{90}{Overall}&
 \rotatebox{90}{Physicians (Proj: 2025)}&
 \rotatebox{90}{Nurses (Proj: 2030)}&
 \rotatebox{90}{\cellcolor{grey}Working age by Old age\ }&
 \rotatebox{90}{\cellcolor{grey}Work force by Old age\ }&
 \rotatebox{90}{Workforce}&
 \rotatebox{90}{Working age}&
 \rotatebox{90}{Workforce}&
 \rotatebox{90}{Working age}&
 \rotatebox{90}{\cellcolor{grey}1 physicians}&
 \rotatebox{90}{\cellcolor{grey}1 nurse}\\
\hline
\multicolumn{2}{|l}{USA}&
 \multicolumn{4}{l}{\cellcolor{grey}}&
 \multicolumn{3}{l}{}&
 \multicolumn{2}{l}{\cellcolor{grey}}&
 \multicolumn{4}{l}{}&
 \multicolumn{2}{l|}{\cellcolor{grey}}\\\hline

1990/1&& 248,6& 71,3& 146,1& 31,2& 127.500& 615,4& 1491,6& 4,68& 4,09& 4,83& 4,21& 11,70& 10,21& 50,7& 20,9\\\hline

1& 2& 3 \\\hline

\end{tabular}

\end{document}
  • Wow that looks almost perfect. Thank you very much! Just one question so i understand that correctly: I found an explanation of hhline telling me what *8(~) and +9(-) stands for, but i couldnt find what \hhline{~~------->{\arrayrulecolor{grey}}-->{\arrayrulecolor{black}}---->{\arrayrulecolor{grey}}-->{\arrayrulecolor{black}}} does mean... – Shiuyin Sep 11 '13 at 20:40
  • @Shiuyin It's a colortbl extension to \hhline the > syntax mimics the > syntax in array preambles and allows declarations that affect the rules (probably only color makes sense) it is a global colour switch so you have to explicitly set it back to black. texdoc colortbl has full info (see Richard of York example:-) – David Carlisle Sep 11 '13 at 20:44
  • @ Davin Carlisle: So then \hhline{~~>{\arrayrulecolor{grey}}---->{\arrayrulecolor{black}}--->{\arrayrulecolor{grey}}-->{\arrayrulecolor{black}}---->{\arrayrulecolor{grey}}-->{\arrayrulecolor{black}} means: 2 blanks followed by 4 grey's, followed by 3 blacks, followed by 2 greys, followed by 4 blacks, followed by 2 greys, followed by black for the next border color? Doesn't work... – Shiuyin Sep 11 '13 at 20:53
  • @Shiuyin doesn't work in what way? see the image I posted (which isn't full line) worked for me, sometimes you have to zoom in a bit, depends on the pdf viewer – David Carlisle Sep 11 '13 at 20:56
  • @Shiuyin oh in your comment above you have a trailing > you can't do that it is an operator that applies to the following segment – David Carlisle Sep 11 '13 at 21:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.