4

I have the following MWE

\documentclass[letterpaper,12pt,oneside,onecolumn,draft,openany]{report}    
\usepackage{caption}
\usepackage{wrapfig, subcaption, siunitx, booktabs, multirow}
\usepackage{graphicx}
\usepackage{float}

\begin{document}
\begin{table}[!htb]    
    \begin{subtable}{.60\linewidth}
      \centering
        \begin{tabular}{c|l|c|c|c|c}
            \toprule
            \parbox[t]{2mm}{\multirow{5}{*}{\rotatebox[origin=c]{90}{age group of susceptible person}}} & & \multicolumn{4}{c}{age group of infectious person} \\
            & & \textbf{0-2} & \textbf{2-5} & \textbf{5-10} & ≥\textbf{10} \\
            \cmidrule(lr{1em}){2-6}
            & \textbf{0-2}   & 2.11  & 0.15  & 0.53   & 0.03   \\      
            & \textbf{2-5}  & 0.55  & 0.40  & 0.50   & 0.12   \\      
            & \textbf{5-10} & 0.56  & 3.68  & 3.61   & 0.13   \\         
            & \textbf{>10}   & 0.55  & 0.55  & 0.81   & 1.43    \\       
            \toprule
        \end{tabular}
    \end{subtable}%
    \begin{subtable}{.60\linewidth}
      \centering
        %\caption{}
        \begin{tabular}{c|l|c|c|c|c}
            \toprule
            \parbox[t]{2mm}{\multirow{5}{*}{\rotatebox[origin=c]{90}{age group of agent $i$}}} & & \multicolumn{4}{c}{age group of infectious person} \\
            & & \textbf{0-2} & \textbf{2-5} & \textbf{5-10} & ≥\textbf{10} \\
            \cmidrule(lr{1em}){2-6}
            & \textbf{0-2}  & 0.75  & 0.80  & 0.98   & 1.0   \\      
            & \textbf{2-5}  & 0.35  & 0.60  & 0.92   & 1.0   \\      
            & \textbf{5-10} & 0.07  & 0.53  & 0.98   & 1.0   \\         
            & \textbf{>10}  & 0.17 & 0.33  & 0.57   & 1.0    \\       
            \toprule
        \end{tabular}
    \end{subtable} 
    \caption{caption}
\end{table}
\end{document}

which produces

example of MWE

Is there a way to make these tables look better? In particular,

  • is there a way to get the 90 degree rotated text to wrap? I tried creating an second empty column but I got errors.
  • is there a way to resize the "data" columns... you see the "10" column is slightly larger than the rest.
3

if i correctly understood your question, than you lookingforsomething like this:

enter image description here

for rotating text in the first column are used packages makecell and rotating:

\documentclass[letterpaper,12pt]{report}
\usepackage{geometry}
\usepackage{siunitx}
\usepackage{booktabs, makecell, multirow, rotating}
\usepackage{graphicx}
\usepackage{caption}
\usepackage{subcaption}

\begin{document}
\begin{table}[!htb]
\settowidth\rotheadsize{age group of}
\setlength\tabcolsep{4pt}
    \begin{subtable}{.48\linewidth}
    \centering
        \begin{tabular}{ c >{\bfseries}l *{4}{S[table-format=1.2]} }
    \toprule
    &       &   \multicolumn{4}{c}{\makecell{age group of\\ infectious person}} \\
    \cmidrule{3-6}
    &       &   \textbf{0-2} & \textbf{2-5} & \textbf{5-10} & ≥\textbf{10} \\
    \midrule
\multirow[t]{4}{*}[-3ex]{\rothead{age group of susceptible person}}
    & 0-2   & 2.11  & 0.15  & 0.53   & 0.03     \\
    & 2-5   & 0.55  & 0.40  & 0.50   & 0.12     \\
    & 5-10  & 0.56  & 3.68  & 3.61   & 0.13     \\
    & >10   & 0.55  & 0.55  & 0.81   & 1.43     \\
    \bottomrule
        \end{tabular}
    \end{subtable}
\hfill
    \begin{subtable}{.48\linewidth}
      \centering
       \begin{tabular}{ c >{\bfseries}l *{3}{S[table-format=1.2]} S[table-format=1.1]}
    \toprule
    &       & \multicolumn{4}{c}{\makecell{age group of\\ infectious person}}  \\
    \cmidrule{3-6}
    &       & \textbf{0-2}  & \textbf{2-5}  & \textbf{5-10} & ≥\textbf{10}  \\
    \midrule
\multirow[t]{4}{*}[-3ex]{\rothead{age group of infectious person}}
    & 0-2   & 0.75  & 0.80  & 0.98   & 1.0      \\
    & 2-5   & 0.35  & 0.60  & 0.92   & 1.0      \\
    & 5-10  & 0.07  & 0.53  & 0.98   & 1.0      \\
    & >10   & 0.17          & 0.33          & 0.57          & 1.0           \\
    \bottomrule
        \end{tabular}
    \end{subtable}
    \caption{caption}
\end{table}
\end{document}

as you can see, i remove all vertical lines. they don't work well with rules defined in the booktabs package. also for numbers are used S columns from siunutx package.

edit: some additiona explanation:

  • c >{\bfseries}l *{4}{S[table-format=1.2]} is definition of table columns layout (instead yours c|l|c|c|c|c

  • \rothead{...} is macro from makecell package. it is designed to rotate contents of table cells for desired angle. for rotating also had to be loaded the rotating package.

    width of \rotcell is set by \settowidth\rotheadsize{age group of} textlonger that this text macro break into more lines.

    for details see documentation for the `makecell package

  • S column type is defined in the siunitx package. it enable aligning numbers in table columns at decimal points. with option [table-format=1.2] is reserved one digit for integers and two digits for decimals. for details see section 5.14 in the package documentation
  • notation *{4}{S[table-format=1.2]} means that in the table are four columns S[table-format=1.2]
  • notation >{\bfseries}lmeans that in this column all contents are in boldface fonts. with it you not need to use\texrbf{...} in each cell in this column.
|improve this answer|||||
  • Thanks, questions what is c >{\bfseries}l *{4}{S[table-format=1.2]} in your tabular heading? and what is rothead – masfenix Nov 13 '18 at 23:42
  • @masfenix, see additional explanation added to answer. – Zarko Nov 14 '18 at 0:16

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.