4

enter image description here

In the above depicted table I am not happy with the positioning of the text "Job category" and "Distribution of 1000...". Ideally, I would like the job category text to be aligned in the centre of the white space in which the text is written. At the moment it is too much aligned to the top hline.

Furthermore, I don't understand from the code why the text "Distribution..." intercepts at the position that it does and isn't aligned to the right (until 1870) of the cell it's written in.

\documentclass[12pt]{report}
    \usepackage{multirow}
    \usepackage{bigstrut}
\makeatletter
\def\hlinewd#1{%
  \noalign{\ifnum0=`}\fi\hrule \@height #1 \futurelet
   \reserved@a\@xhline}
\makeatother

    \begin{document}
\begin{table}[h!]
  \centering
  \caption{Shift in job distribution 1870 - 1910}
  \scriptsize
    \begin{tabular}{l|c|c|c|c|c}
    \hlinewd{1.25pt}
    \multicolumn{1}{c}{\multirow{2}[4]{*}{Job category}} & \multicolumn{5}{p{3.5cm}}{Distribution of 1000 individuals of the overall population} \bigstrut\\
\cline{2-6}    \multicolumn{1}{c}{} & 1910  & 1900  & 1888  & 1880  & 1870 \bigstrut\\
    \hline
    A. Primary production & 277   & 332   & 388   & 406   & 429 \bigstrut[t]\\
    Thereof agriculture and cattle industry & 261   & 316   & 374   & 391   & 416 \\
    B. Trade and industry & 427   & 417   & 378   & 390   & 367 \\
    C. Commerce & 101   & 86    & 73    & 72    & 66 \\
    D. Transport & 63    & 51    & 34    & 28    & 18 \\
    E. Public administration, science, arts & 57    & 51    & 44    & 43    & 43 \\
    F. Changing wage labour  & 10    & 6     & 10    & 6     & 7 \\
    G. Living off pensions and benefits & 65    & 57    & 73    & 55    & 70 \bigstrut[b]\\
    \hlinewd{1.25pt}
    \end{tabular}%
    \vspace{5pt}
    \captionsetup{font={footnotesize}}
    \caption*{Source: Steinemann et al. (1921), p. 23, own illustration}
  \label{tab:addlabel}%
\end{table}%

\end{document}
1
  • 1
    You state, " I don't understand from the code why the text 'Distribution...' intercepts at the position that it does and isn't aligned to the right (until 1870)". That would be because you've set the width of the p column to 3.5cm; 4.5cm might be more to your liking.
    – Mico
    Jan 12, 2015 at 20:14

2 Answers 2

2

You fixed-width p-column is too narrow. You can calculate the actual width to have a more precise measurement if needed, or specify something close to it (the actual width, under \scriptsize is around 133pt):

enter image description here

\documentclass[12pt]{report}
\usepackage{bigstrut,booktabs,siunitx}
\makeatletter
\def\hlinewd#1{%
  \noalign{\ifnum0=`}\fi\hrule \@height #1 \futurelet
   \reserved@a\@xhline}
\makeatother
\begin{document}

\scriptsize

\newlength{\specialcolwidth}
\settowidth{\specialcolwidth}{\scriptsize 19101900188818801870}
\addtolength{\specialcolwidth}{8\tabcolsep}

\begin{tabular}{l|c|c|c|c|c}
  \hlinewd{1.25pt}
  \multicolumn{1}{c}{\raisebox{-.5\normalbaselineskip}[0pt][0pt]{Job category}} & 
    \multicolumn{5}{p{\specialcolwidth}}{Distribution of 1000 individuals of the overall population} \bigstrut\\
  \cline{2-6}
  \multicolumn{1}{c}{} & 1910  & 1900  & 1888  & 1880  & 1870 \bigstrut\\
  \hline
  A. Primary production & 277   & 332   & 388   & 406   & 429 \bigstrut[t]\\
  Thereof agriculture and cattle industry & 261   & 316   & 374   & 391   & 416 \\
  B. Trade and industry & 427   & 417   & 378   & 390   & 367 \\
  C. Commerce & 101   & 86    & 73    & 72    & 66 \\
  D. Transport & 63    & 51    & 34    & 28    & 18 \\
  E. Public administration, science, arts & 57    & 51    & 44    & 43    & 43 \\
  F. Changing wage labour  & 10    & 6     & 10    & 6     & 7 \\
  G. Living off pensions and benefits & 65    & 57    & 73    & 55    & 70 \bigstrut[b]\\
  \hlinewd{1.25pt}
\end{tabular}%

\bigskip

\begin{tabular}{ l *{5}{S[table-format=4]} }
  \toprule
  \multicolumn{1}{c}{\raisebox{-.5\normalbaselineskip}[0pt][0pt]{Job category}} & 
    \multicolumn{5}{p{\specialcolwidth}}{\centering Distribution of 1000 individuals of the overall population} \\
  \cmidrule{2-6}
                                          & 1910 & 1900 & 1888 & 1880 & 1870 \\
  \midrule
  A. Primary production                   &  277 &  332 &  388 &  406 &  429 \\
  Thereof agriculture and cattle industry &  261 &  316 &  374 &  391 &  416 \\
  B. Trade and industry                   &  427 &  417 &  378 &  390 &  367 \\
  C. Commerce                             &  101 &   86 &   73 &   72 &   66 \\
  D. Transport                            &   63 &   51 &   34 &   28 &   18 \\
  E. Public administration, science, arts &   57 &   51 &   44 &   43 &   43 \\
  F. Changing wage labour                 &   10 &    6 &   10 &    6 &    7 \\
  G. Living off pensions and benefits     &   65 &   57 &   73 &   55 &   70 \\
  \bottomrule
\end{tabular}%

\end{document}

My solution also presents an siunitx column layout with booktabs (and no use of multirow).

4

As Mico says in his comment p{3.5cm} is not enough in the \multicolumn, change it to p{4.5cm}.

Then adjust the optional argument of \multirow (I've changed it from 4 to 8).

MWE

\documentclass[12pt]{report}
    \usepackage{multirow,caption}
    \usepackage{bigstrut}
\makeatletter
\def\hlinewd#1{%
  \noalign{\ifnum0=`}\fi\hrule \@height #1 \futurelet
   \reserved@a\@xhline}
\makeatother

    \begin{document}
\begin{table}[h!]
  \centering
  \caption{Shift in job distribution 1870 - 1910}
  \scriptsize
    \begin{tabular}{l|c|c|c|c|c}
    \hlinewd{1.25pt}
    \multicolumn{1}{c}{\multirow{2}[8]{*}{Job category}} & \multicolumn{5}{p{4.5cm}}{Distribution of 1000 individuals of the overall population} \bigstrut\\
\cline{2-6}    \multicolumn{1}{c}{} & 1910  & 1900  & 1888  & 1880  & 1870 \bigstrut\\
    \hline
    A. Primary production & 277   & 332   & 388   & 406   & 429 \bigstrut[t]\\
    Thereof agriculture and cattle industry & 261   & 316   & 374   & 391   & 416 \\
    B. Trade and industry & 427   & 417   & 378   & 390   & 367 \\
    C. Commerce & 101   & 86    & 73    & 72    & 66 \\
    D. Transport & 63    & 51    & 34    & 28    & 18 \\
    E. Public administration, science, arts & 57    & 51    & 44    & 43    & 43 \\
    F. Changing wage labour  & 10    & 6     & 10    & 6     & 7 \\
    G. Living off pensions and benefits & 65    & 57    & 73    & 55    & 70 \bigstrut[b]\\
    \hlinewd{1.25pt}
    \end{tabular}%
    \vspace{5pt}
    \captionsetup{font={footnotesize}}
    \caption*{Source: Steinemann et al. (1921), p. 23, own illustration}
  \label{tab:addlabel}%
\end{table}%

\end{document} 

Output:

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .