# Complicated footnote within longtable environment

I have a footnote that explains color coding within a complicated longtable. I would like this footnote to appear on all pages of the longtable. However, the way I have it now, the footnote itself is within a longtable of its own.

Is there any other way I can typeset this footnote and have it appear on all pages of the longtable? Any ideas would be most welcome.

Please see code and snapshot below for a minimum working example for what I have right now:

\documentclass[6pt]{article}
\usepackage[portrait, total={5.45in, 8.5in}, top=1.25in, bottom=1.25in, right=1.25in, left=1.5in, centering]{geometry}
\usepackage{longtable}
\usepackage{bm}
\usepackage[table]{xcolor}
\usepackage[none]{hyphenat}
\usepackage[T1]{fontenc}
\usepackage[default]{cantarell}
\usepackage{booktabs}
\usepackage{array}

\pagestyle{empty}
\renewcommand{\familydefault}{\sfdefault}
\renewcommand{\arraystretch}{1.25}
\usepackage{arydshln}
\newcolumntype{x}[1]{>{\raggedright}p{#1}}
\setlength{\tabcolsep}{4pt}
\begin{document}

\begin{center}
\scriptsize{\textbf{A longtable with two groups}}\end{center}
\setlength\LTleft{0in}
\setlength\LTright{1.25in}
\setlength\LTpre{-0.3cm}
\setlength\LTpost{0in}
\newcommand{\CTPanel}[1]{%
\multicolumn{1}{>{\columncolor{white}}r|}{#1}}
\centering
p{0.3cm}!{\color{white}\vrule width 4pt}
p{0.3cm}!{\color{white}\vrule}
p{0.3cm}!{\color{white}\vrule}
p{0.3cm}!{\color{white}\vrule}
p{0.3cm}!{\color{white}\vrule}
p{0.3cm}!{\color{white}\vrule}
p{0.3cm}!{\color{white}\vrule}
p{0.3cm}!{\color{white}\vrule}
p{0.3cm}!{\color{white}\vrule}
p{0.3cm}!{\color{white}\vrule}}
\hiderowcolors
&\multicolumn{9}{c}{First Group}&\multicolumn{9}{c}{Second Group}\\\cmidrule(lr){2-10}\cmidrule(lr){11-19}
something&\multicolumn{2}{c}{AB} & \multicolumn{3}{c}{ABCD} &
\multicolumn{4}{c}{ABCD EFGH}&\multicolumn{2}{c}{AB} & \multicolumn{3}{c}{ABCD} & \multicolumn{4}{c}{ABCD EFGH}\\\cmidrule(lr){2-3}\cmidrule(lr){4-6}\cmidrule(lr){7-10}\cmidrule(lr){11-12}\cmidrule(lr){13-15}\cmidrule(lr){16-19}
Characteristics & + & - & I & II & III & $L^{A}$ & $L^{B}$ & $H^{+}$ & TN & + & - & I & II & III & $L^{A}$ & $L^{B}$ & $H^{+}$ & TN\\
\specialrule{0.01em}{0.1em}{0em}
\specialrule{0.01em}{0em}{0em}
\endfoot
\showrowcolors
some variable &+&+&-&+&+&-&-&-&-&-&+&+&-&-&+&+&-&-\\
some other variable &+&+&-&+&+&-&-&-&-&-&+&+&-&-&+&+&-&-\\
some other variable &+&+&-&+&+&-&-&-&-&-&+&+&-&-&+&+&-&-\\
fourth variable &+&+&-&+&+&-&-&-&-&-&+&+&-&-&+&+&-&-\\
fifth variable &+&+&-&+&+&-&-&-&-&-&+&+&-&-&+&+&-&-\\
yet other variable &+&+&-&+&+&-&-&-&-&-&+&+&-&-&+&+&-&-\\
\end{longtable}
\scriptsize
%Complicated legend begins
\begin{longtable}{llllll}
\hiderowcolors
\multicolumn{6}{l}{\textbf{LEGEND}}\\
{\cellcolor{tableShade4}${\bm+^m}$}&: Monotonic Increase, Significant&
{\cellcolor{tableShade6}${\bm-^m}$}&: Monotonic Decrease, Significant&
{\cellcolor{tableShade1}${\bm*}$}&: Non-linear, Significant \\

{\cellcolor{tableShade4}${\bm+}$}&: Increase, Significant&
{\cellcolor{tableShade6}${\bm-}$}&: Decrease, Significant&
{\cellcolor{tableShade1}${\bm\pm}$}&: Mixed, Significant    {\cellcolor{tableShade5}$+^m$}&: Monotonic Increase&
{\cellcolor{tableShade7}$-^m$}&: Monotonic Decrease&
{\cellcolor{tableShade2}$\pm$}&: Mixed    {\cellcolor{tableShade5}$+$}&: Increase&
{\cellcolor{tableShade7}$-$}&: Decrease&
-&: Not computed\\
\multicolumn{6}{l}{AB: ABbreviation}\\
\end{longtable}
\end{document}


\endhead
%Complicated legend begins at the top of longtable in the \endfoot area
\noalign{\raggedright
\scriptsize
{
\begin{tabular}{llllll}
\hiderowcolors
\multicolumn{6}{l}{\textbf{LEGEND}}\\
{\cellcolor{tableShade4}${\bm+^m}$}&: Monotonic Increase, Significant&
{\cellcolor{tableShade6}${\bm-^m}$}&: Monotonic Decrease, Significant&
{\cellcolor{tableShade1}${\bm*}$}&: Non-linear, Significant \\
{\cellcolor{tableShade4}${\bm+}$}&: Increase, Significant&
{\cellcolor{tableShade6}${\bm-}$}&: Decrease, Significant&
{\cellcolor{tableShade1}${\bm\pm}$}&: Mixed, Significant\\
{\cellcolor{tableShade5}$+^m$}&: Monotonic Increase&
{\cellcolor{tableShade7}$-^m$}&: Monotonic Decrease&
{\cellcolor{tableShade2}$\pm$}&: Mixed\\
{\cellcolor{tableShade5}$+$}&: Increase&
{\cellcolor{tableShade7}$-$}&: Decrease&
-&: Not computed\\
\multicolumn{6}{l}{AB: ABbreviation}\\
\end{tabular}
}
\endfoot


It works and the legend is now flush left with the table!

An addition to this problem is when you do not specify the LTleft and LTright lengths in your longtable preamble. In this case, the \noalign trick above does not work. Here's the solution, all thanks to David Carlisle's incredibly useful comments in TeX, LaTeX and Friends chat:

Try:

\multicolumn{8}{@{}p {6in}}
{\raggedright
\begin{tabular}{llllll}
\hiderowcolors
\multicolumn{6}{@{}l}{Variables with as asterisk(*) have corresponding continuous forms. Please also see Table x.x for summary from the analyses using these continuous forms.}\\
\multicolumn{6}{@{}l}{\textbf{LEGEND}}\\
{\cellcolor{tableShade4}${\bm+^m}$}&: Monotonic Increase, Significant&
{\cellcolor{tableShade6}${\bm-^m}$}&: Monotonic Decrease, Significant&
{\cellcolor{tableShade1}${\bm*}$}&: Non-linear, Significant \\
{\cellcolor{tableShade4}${\bm+}$}&: Increase, Significant&
{\cellcolor{tableShade6}${\bm-}$}&: Decrease, Significant&
{\cellcolor{tableShade1}${\bm\pm}$}&: Mixed, Significant    {\cellcolor{tableShade5}$+^m$}&: Monotonic Increase&
{\cellcolor{tableShade7}$-^m$}&: Monotonic Decrease&
{\cellcolor{tableShade2}$\pm$}&: Mixed    {\cellcolor{tableShade5}$+$}&: Increase&
{\cellcolor{tableShade7}$-$}&: Decrease&
-&: Not computed\\
\end{tabular}
}


Notice how @{} in the multicolumn specification removes the space before the content starts in a cell. So it forces the legend to start at the wall of the longtable and ensures that the small tabular also does not introduce any extra space on the left.The legend now appears flush left with wherever the table edge might be.

Many thanks!

• Does it have to be a footnote (rather than just put it in the table foot, which is put on every page automatically)? Mar 2 '12 at 21:18
• I tried putting it before \endfoot in the longtable format but it results in somewhat ugly results. Is that what you meant? It certainly does not have to be a footnote. I just need the legend to appear below the table on all pages Mar 2 '12 at 21:24
• you can if you wish use exactly the format you have there, stick the entire legend into a tabular envronment in a multicolumn in the longtable foot. Mar 2 '12 at 22:01
• thanks so much for that idea! I tried it just now. The tabular environment before the \endfoot works but I am not sure how to put all of that in a multicolumn environment. It doesn't compile. Adding my attempted code to the post above. Could you please take a look? Mar 2 '12 at 22:13
• I was doing the same, actually if you got an error about the argument of multicolumn that's due to the blank line but actually it looked a bit better with noalign, see the answer I posted a few minutes ago Mar 2 '12 at 22:19

\documentclass[6pt]{article}
\usepackage[portrait, total={5.45in, 8.5in}, top=1.25in, bottom=1.25in, right=1.25in, left=1.5in, centering]{geometry}
\usepackage{longtable}
\usepackage{bm}
\usepackage[table]{xcolor}
\usepackage[none]{hyphenat}
\usepackage[T1]{fontenc}
%\usepackage[default]{cantarell}
\usepackage{booktabs}
\usepackage{array}

\pagestyle{empty}
\renewcommand{\familydefault}{\sfdefault}
\renewcommand{\arraystretch}{1.25}
\usepackage{arydshln}
\newcolumntype{x}[1]{>{\raggedright}p{#1}}
\setlength{\tabcolsep}{4pt}
\begin{document}

\begin{center}
\scriptsize{\textbf{A longtable with two groups}}\end{center}
\setlength\LTleft{0in}
\setlength\LTright{1.25in}
\setlength\LTpre{-0.3cm}
\setlength\LTpost{0in}
\newcommand{\CTPanel}[1]{%
\multicolumn{1}{>{\columncolor{white}}r|}{#1}}
\centering
p{0.3cm}!{\color{white}\vrule width 4pt}
p{0.3cm}!{\color{white}\vrule}
p{0.3cm}!{\color{white}\vrule}
p{0.3cm}!{\color{white}\vrule}
p{0.3cm}!{\color{white}\vrule}
p{0.3cm}!{\color{white}\vrule}
p{0.3cm}!{\color{white}\vrule}
p{0.3cm}!{\color{white}\vrule}
p{0.3cm}!{\color{white}\vrule}
p{0.3cm}!{\color{white}\vrule}}
\hiderowcolors
&\multicolumn{9}{c}{First Group}&\multicolumn{9}{c}{Second Group}\\\cmidrule(lr){2-10}\cmidrule(lr){11-19}
something&\multicolumn{2}{c}{AB} & \multicolumn{3}{c}{ABCD} &
\multicolumn{4}{c}{ABCD EFGH}&\multicolumn{2}{c}{AB} & \multicolumn{3}{c}{ABCD} & \multicolumn{4}{c}{ABCD EFGH}\\\cmidrule(lr){2-3}\cmidrule(lr){4-6}\cmidrule(lr){7-10}\cmidrule(lr){11-12}\cmidrule(lr){13-15}\cmidrule(lr){16-19}
Characteristics & + & - & I & II & III & $L^{A}$ & $L^{B}$ & $H^{+}$ & TN & + & - & I & II & III & $L^{A}$ & $L^{B}$ & $H^{+}$ & TN\\
\specialrule{0.01em}{0.1em}{0em}
\noalign{
\scriptsize
%Complicated legend begins
\begin{tabular}{llllll}
\hiderowcolors
\multicolumn{6}{l}{\textbf{LEGEND}}\\
{\cellcolor{tableShade4}${\bm+^m}$}&: Monotonic Increase, Significant&
{\cellcolor{tableShade6}${\bm-^m}$}&: Monotonic Decrease, Significant&
{\cellcolor{tableShade1}${\bm*}$}&: Non-linear, Significant \\
{\cellcolor{tableShade4}${\bm+}$}&: Increase, Significant&
{\cellcolor{tableShade6}${\bm-}$}&: Decrease, Significant&
{\cellcolor{tableShade1}${\bm\pm}$}&: Mixed, Significant\\
{\cellcolor{tableShade5}$+^m$}&: Monotonic Increase&
{\cellcolor{tableShade7}$-^m$}&: Monotonic Decrease&
{\cellcolor{tableShade2}$\pm$}&: Mixed\\
{\cellcolor{tableShade5}$+$}&: Increase&
{\cellcolor{tableShade7}$-$}&: Decrease&
-&: Not computed\\
\multicolumn{6}{l}{AB: ABbreviation}\\
\end{tabular}
}
\endfoot
\specialrule{0.01em}{0em}{0em}
\showrowcolors
some variable &+&+&-&+&+&-&-&-&-&-&+&+&-&-&+&+&-&-\\
some other variable &+&+&-&+&+&-&-&-&-&-&+&+&-&-&+&+&-&-\\
some other variable &+&+&-&+&+&-&-&-&-&-&+&+&-&-&+&+&-&-\\
\newpage
fourth variable &+&+&-&+&+&-&-&-&-&-&+&+&-&-&+&+&-&-\\
fifth variable &+&+&-&+&+&-&-&-&-&-&+&+&-&-&+&+&-&-\\
yet other variable &+&+&-&+&+&-&-&-&-&-&+&+&-&-&+&+&-&-\\
\end{longtable}
\end{document}

• Don't want to sound too nitpicky now that the major headache is gone but do you think there is some way to align the footnote to the left edge of the table? Mar 2 '12 at 22:30
• Yes since you have the LT set with \setlength\LTleft{0in} so you know where its left edge is (flush left). Just stick \noindent before the tabular and it should all work. You really ought to put some stretch in \setlength\LTright{\fill} as otherwise you are asking tex to make the table a fixed width but giving no stretch points. In general if you set LTleft to some non zero non stretch space you can just use a \noindent\hspace*{\LTleft}\begin{tabular... I should think Mar 2 '12 at 22:40
• Sorry as I used \noalign not all LaTeX's state is restored, put \noalign{\raggedright \begin{tabular.... and the legend will go flush left. Mar 2 '12 at 22:58
• I thought someone must have asked what is stretch (known as glue in TeX) this answers a related point tex.stackexchange.com/questions/21022/… Mar 2 '12 at 23:17
• If you set ltleft and ltright to fixed lengths it is like using a standard tabular* specifying a fixed width for a table but not putting any glue with @{\extracolumnsep{\fill} to allow tex to stretch the table to the requested width. If the natural width of the table is less than the text width you must flush left or right or center, or if you want to force both edges to be justified to the margin you have to allow the columns to be stretched apart with  @{\extracolumnsep{\fill}` Mar 2 '12 at 23:18