# LaTeX typeset multiple comparisons

So, here goes! I'm teaching an applied stats course and was wondering whether anyone can advise me on how to display multiple comparisons in the context of ANOVA. I.e. Tukey's HSD.

For example, if you have four treatments then we will often want to summarise the information from pairwise comparisons like this (solid lines, not dashed, and not so much vertical space):

D B C A F E
-----   ---
-----


which indicates that D is significantly different from A, F & E; D, B, C do not differ significantly from each other etc. In other words, we have a line connecting treatments which do not differ significantly.

Something like this would work, but there must be a better way of doing this:

\begin{tabular}{cccccc}
\cline{2-4}
D & B & C & A & F & E\tabularnewline
\hline
&  &  &  &  & \tabularnewline
\end{tabular}


Also a table doesn't work nicely in more complex situations.

How do they typeset this in most stats texts?

• We'd be happy to give you a few pointers, but could you post a link to an actual example of the diagrams you're interested in? – jubobs Oct 6 '13 at 16:35
• There's an example of this in the Encyclopedia of Research Design, with the additional observation that this might not be the best way to display the results, but that a table of the probability values and confidence levels might work better. – Jake Oct 6 '13 at 17:43
• @Jake thanks for proving that link. Jubobs, kindly have a look at that link, example is in figure one. I am well aware of the problems with displaying the results that way, but it is a useful device for students to learn how to interpret the tables properly. I.e. they can tell me this particular difference is significant but they struggle to interpret the meaning of several CIs together. Service courses... I need to cater for a very diverse group of students with varying maths skills :-( – Stefan Oct 7 '13 at 10:05

This solution introduces \UL (underline), in which the argument is the letter followed by a space-separated list of dots . and dashes -, signifying the levels of underline. A dot signifies no underline of the letter, whereas a dash signifies an underline at that level. The underline thickness is settable with \thk and the separation between the underline levels is accomplished with \setstackgap{S}{length}.

This MWE assumes your inputs will be non-descending capital letters. However, if your input will contain descenders, the line \def\thesavedstack{\argi} should be replaced with \def\thesavedstack{\rule[-.6\dp\strutbox]{0pt}{0pt}\argi}.

\documentclass{article}
\usepackage{stackengine}
\newcounter{index}
\newcounter{maxlines}
\newcommand\UL[1]{%
\getargsC{#1}%
\setcounter{maxlines}{\narg}%
\def\thesavedstack{\argi}%
\setcounter{index}{1}%
\whiledo{\theindex<\themaxlines}{%
\stepcounter{index}%
\if\csname arg\roman{index}\endcsname-%
\def\themark{\rule{\widthof{\argi}}{\thk}}%
\else%
\def\themark{\rule{0ex}{\thk}}%
\fi%
\savestack{\thesavedstack}{\stackunder{\thesavedstack}{\themark}}%
}%
\thesavedstack
}
\parskip 1em
\def\thk{.1ex}
\setstackgap{S}{2pt}
\begin{document}
\UL{D - .}\UL{B - -}\UL{C - -}\UL{A . -}\UL{F - .}\UL{E - .}

\UL{D - . -}\UL{B - - .}\UL{C - - .}\UL{A . - -}\UL{F - . -}\UL{E - . -}
\end{document}


Here's the result using the descender trick mentioned above: