# Big curly brackets and rotated text around table

I have a rather cramped looking table here showing the chance of a nurse touching a surface type given (s)he is doing a certain type of care. I would like to make a large curly bracket to the left of the rows with a vertical label (Care type), and one above the columns saying (Surface category). Any thoughts? Also I'm very open to any suggestion of how best to display this table at your discretion.

\documentclass{article}
\usepackage{amsmath} % provides \text command
\begin{document}
$$\begin{array}{*{6}{c}} &\text{Equipment}&\text{Patient}&\text{Hygiene products}&\text{Near-bed objects}&\text{Far-bed objects}\\ \text{Direct Care}&\frac{49}{192}&\frac{170}{913}&\frac{18}{173}&\frac{79}{392}&\frac{21}{83}\\ \text{Housekeeping}&\frac{22}{89}&\frac{7}{89}&\frac{6}{89}&\frac{35}{89}&\frac{19}{89}\\ \text{Mealtimes}&0&\frac{6}{55}&\frac{2}{11}&\frac{31}{55}&\frac{8}{55}\\ \text{Medication round}&\frac{23}{429}&\frac{23}{143}&\frac{7}{39}&\frac{50}{143}&\frac{10}{39}\\ \text{Misc.}&\frac{4}{165}&\frac{19}{165}&\frac{8}{33}&\frac{10}{33}&\frac{52}{165}\\ \text{Personal Care}&\frac{3}{89}&\frac{15}{89}&\frac{19}{89}&\frac{36}{89}&\frac{16}{89}\\ \text{Overall}&\frac{7}{233}&\frac{34}{233}&\frac{54}{233}&\frac{80}{233}&\frac{58}{233}\\ \end{array}$$
\end{document}


-
I assume that the table you show was not generated by the code you posted (which generates lots of syntax errors) undefined command \text and missing $ errors for every entry (as you can not have math in p columns) – David Carlisle Mar 25 '13 at 18:47 You're right, it wouldn't compile, so I used mathjax on math.stackexchange.com. I don't understand why I need$ for every entry if I've put it in , could you clarify please? – HCAI Mar 25 '13 at 18:56
Please normalize your data. It's evil to force someone read this table. – percusse Mar 25 '13 at 19:27
I've done a minimalist edit on the code you've provided so that it can actually compile without lots of error messages – Mico Mar 25 '13 at 20:16
@percusse I have hiven your comment a thumbs up because I agree. When you say normalise... to what exactly are you referring? could you give me an example? I think in hindsight I will display this data pictorially as a bar graph. – HCAI Mar 26 '13 at 16:15

How about the following look. It dispenses with the need to ask your readers to crane their necks by 90 degrees, and it also provides a less cramped appearance. :-)

\documentclass{article}
\usepackage[margin=1in]{geometry}
\usepackage{amsmath,booktabs}
\begin{document}
$\begin{array}{@{} l *{5}{c} @{}} \toprule \textbf{Care type} & \multicolumn{5}{c@{}}{\textbf{Surface category}}\\ \cmidrule(l){2-6} &\text{Equipment} &\text{Patient} &\text{Hygiene} &\text{Near-bed} &\text{Far-bed}\\ & & & \text{products} & \text{objects} & \text{objects}\\ \midrule \text{Direct Care}&\frac{49}{192}&\frac{170}{913}&\frac{18}{173}&\frac{79}{392}&\frac{21}{83}\\[0.7ex] \text{Housekeeping}&\frac{22}{89}&\frac{7}{89}&\frac{6}{89}&\frac{35}{89}&\frac{19}{89}\\[0.7ex] \text{Mealtimes}&0&\frac{6}{55}&\frac{2}{11}&\frac{31}{55}&\frac{8}{55}\\[0.7ex] \text{Medication round}&\frac{23}{429}&\frac{23}{143}&\frac{7}{39}&\frac{50}{143}&\frac{10}{39}\\[0.7ex] \text{Misc.}&\frac{4}{165}&\frac{19}{165}&\frac{8}{33}&\frac{10}{33}&\frac{52}{165}\\[0.7ex] \text{Personal Care}&\frac{3}{89}&\frac{15}{89}&\frac{19}{89}&\frac{36}{89}&\frac{16}{89}\\[0.7ex] \text{Overall}&\frac{7}{233}&\frac{34}{233}&\frac{54}{233}&\frac{80}{233}&\frac{58}{233}\\ \bottomrule \end{array}$
\end{document}


Incidentally, I can't help but wonder what the purpose may be of expressing the numbers as exact fractions rather than as rounded decimal fractions (with either 3 or 4 digits of precision, say). I suspect that many potential readers might be better served with an approximate number such as 0.186 rather than with the exact value of 170/913.

-
This looks fantastic! Thank you for your nice work! In retrospect the decimals are easier to read. – HCAI Mar 25 '13 at 21:12
@HCAI - Glad you like the look. :-) If you do end up typesetting the numbers as decimal fractions, you could use a tabular environment rather than the array environment currently in use. As a benefit to switching to a tabular, you won't need to encase all the non-numeric cells with \text statements. – Mico Mar 25 '13 at 21:21
This is a very robust but versatile environment that you have provided! Again many thanks! By the way in your opinion how would you force latex to center this table if it got wider. Ie stop it running off the right hand margin. – HCAI Mar 25 '13 at 21:25
@HCAI - For information on "making room" for a table that's slightly wider than the text block see, e.g., tex.stackexchange.com/q/39435/5001. – Mico Mar 25 '13 at 21:52

a p column is a parbox so it takes you out of math mode. The edited question changed that to c but had the syntax of * incorrrect.

I added some braces (which requires a bit of hand tuning of the spaces) and opened up the display with \arraystretch.

\documentclass{article}
\usepackage{graphicx}
\begin{document}

\renewcommand\arraystretch{1.5}

xxxxxxxx

\vspace{40pt}
\rotatebox[origin=c]{90}{\textbf{Care Type}}\left\{ \begin{array}{*{6}{c}} \noalign{\vspace{-40pt}} &\multicolumn{5}{c}{\textbf{Surface Category}}\\[-10pt] &\multicolumn{5}{c}{\downbracefill}\\ &\mbox{Equipment}&\mbox{Patient}&\mbox{Hygiene products}&\mbox{Near-bed objects}&\mbox{Far-bed objects}\\ \mbox{Direct Care}&\frac{49}{192}&\frac{170}{913}&\frac{18}{173}&\frac{79}{392}&\frac{21}{83}\\ \mbox{Housekeeping}&\frac{22}{89}&\frac{7}{89}&\frac{6}{89}&\frac{35}{89}&\frac{19}{89}\\ \mbox{Mealtimes}&0&\frac{6}{55}&\frac{2}{11}&\frac{31}{55}&\frac{8}{55}\\ \mbox{Medication round}&\frac{23}{429}&\frac{23}{143}&\frac{7}{39}&\frac{50}{143}&\frac{10}{39}\\ \mbox{Misc.}&\frac{4}{165}&\frac{19}{165}&\frac{8}{33}&\frac{10}{33}&\frac{52}{165}\\ \mbox{Personal Care}&\frac{3}{89}&\frac{15}{89}&\frac{19}{89}&\frac{36}{89}&\frac{16}{89}\\ \mbox{Overall}&\frac{7}{233}&\frac{34}{233}&\frac{54}{233}&\frac{80}{233}&\frac{58}{233}\\ \end{array} \right.
\end{document}

-
Thank you very very much for your lovely work! I'm amazed every day by what LaTeX has to offer! – HCAI Mar 25 '13 at 21:13
And I'm amazed every day by what David has to offer in this forum. :) He is a true TeXpert! – Svend Tveskæg Mar 25 '13 at 22:29

this I find somewhat more pleasing (I'm not particularly fond of center alignment in tables). The look as well as the code might still need some refinement, though. I second Mico's suggestion: use 0.186 etc. instead. Makes things easier for both reader and typographer.

\documentclass[12pt]{article}
\usepackage[T1]{fontenc}
\usepackage{lmodern}

\DeclareInstance{xfrac}{lmss}{text}
{
numerator-font = lmss,
denominator-font = lmss,
scale-factor = 1.333,
h-scale = 1
}

\begin{document}
\begin{table}
\footnotesize% = 10pt
\sffamily%
\begin{tabular}{l p{.12\textwidth} p{.12\textwidth} p{.12\textwidth} p{.12\textwidth} p{.12\textwidth}}
& \mbox{\emph{surface category}}\\

\cmidrule(){2-6}

\raisebox{-15pt}{\emph{care type}}&\raisebox{-15pt}{\textbf{equipment}}&\raisebox{-15pt}{\textbf{patient}}&\textbf{hygiene products}&\textbf{near-bed objects}&\textbf{far-bed objects}\\

\cmidrule(r){1-1}\cmidrule(){2-6}

{direct care}&\sfrac{49}{192}&\sfrac{170}{913}&\sfrac{18}{173}&\sfrac{79}{392}&\sfrac{21}{83}\\
{housekeeping}&\sfrac{22}{89}&\sfrac{7}{89}&\sfrac{6}{89}&\sfrac{35}{89}&\sfrac{19}{89}\\
{mealtimes}&0&\sfrac{6}{55}&\sfrac{2}{11}&\sfrac{31}{55}&\sfrac{8}{55}\\
{medication round}&\sfrac{23}{429}&\sfrac{23}{143}&\sfrac{7}{39}&\sfrac{50}{143}&\sfrac{10}{39}\\
{misc.}&\sfrac{4}{165}&\sfrac{19}{165}&\sfrac{8}{33}&\sfrac{10 }{33}&\sfrac{52}{165}\\
{personal care}&\sfrac{3}{89}&\sfrac{15}{89}&\sfrac{19}{89}&\sfrac{36}{89}&\sfrac{16}{89}\\
{overall}&\sfrac{7}{233}&\sfrac{34}{233}&\sfrac{54}{233}&\sfrac{80}{233}&\sfrac{58}{233}\\

\cmidrule(r){1-1}\cmidrule(){2-6}
\end{tabular}
\end{table}
\end{document}

-

As far as you asked, a suggestion: do not use curly brackets. Really, there is no need in them, just use a straight line and a column header instead. Also, a stack of fractions looks unreadable, and a / looks much like a visual noise. Check out this ctable example:

\documentclass{article}
\usepackage{amsmath} % provides  command
\usepackage{lmodern}
\usepackage[T1]{fontenc}
\usepackage{caption}
\usepackage{ctable}
\begin{document}
\listoftables

\global\def\f#1/#2 {\ensuremath{^{#1}}&\ensuremath{_{#2}}}
\global\def\row #1|#2|#3|#4|#5|#6 { #1&\f #2&\f #3&\f #4&\f #5&\f #6 }

\global\def\subhdr #1|#2|#3|#4|#5 {%
\multicolumn{2}{X}{#1}
&\multicolumn{2}{X}{#2}
&\multicolumn{2}{X}{#3}
&\multicolumn{2}{X}{#4}
&\multicolumn{2}{X}{#5}}

\ctable[%
caption ={The chances of a nurse
touching a surface type given (s)he is doing a certain type of care},
label = tab:1,
pos = ht,
left,
width = 130mm,
mincapwidth = 160mm,
footerwidth = 130mm,
%doinside = \scriptsize
]{l*{5}{r@{\extracolsep{0pt}}l}}{
\tnote[a]{Comment: }
%\tnote[b]{}
}{  \FL
%
&\multicolumn{10}{c}{Surface category}\NN
\cmidrule(r){2-11}
{Care type}    & \subhdr          {Equipment} |{Patient}|{Hygiene products}|{Near-bed objects}|{Far-bed objects} \ML
\row Direct Care              |49/192     |170/913 |18/173          |79/392          |21/83 \\
\row Housekeeping             |22/89      |7/89    |6/89            |35/89           |19/89 \\
\row Mealtimes{\tmark[a]}     |0/{}       |6/55    |2/11            |31/55           |8/55 \\
\row Medication round         |23/429     |23/143  |7/39            |50/143          |10/39 \\
\row Misc.                    |4/165      |19/165  |8/33            |10/33           |52/165 \\
\row Personal Care            |3/89       |15/89   |19/89           |36/89           |16/89 \\
\row Overall                  |7/233      |34/233  |54/233          |80/233          |58/233
\LL
}
\end{document}


Edit: An approach suggested by Daniel in Is it possible to use the pipe character, |, to separate cells in a table? was used in the \row definition.

-
This looks nice too, thank you very much! Fascinating, everybody has a different way of making a table! :) After all this, would you, as a reader prefer to see a graph of some sort perhaps? – HCAI Mar 26 '13 at 14:52
@HCAI: Editors/reviewers usually are not happy with the redundancy of information. Of course, the author can insist on including both a table and a picture, but it would be better if the picture illustrates something more to the reader - maybe a trend or whatever. – g.kov Mar 26 '13 at 15:05
I have this data in probability bar graph per care type. Perhaps the audience doesn't need to know the exact values but is happy with a pictorial comparison. Then of course reproducibility of results is harder for the reader, but nevermind. Again thank you for the table, it will always be useful for me to refer to a correctly created version. Regards – HCAI Mar 26 '13 at 16:14