12

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}
\definecolor{tableShade2}{HTML}{F1F5FA}
\definecolor{tableShade}{HTML}{FAFAFD}
\definecolor{tableShade3}{HTML}{dddddd}
\definecolor{tableShade4}{HTML}{C2A5CF}
\definecolor{tableShade5}{HTML}{E7D4E8}
\definecolor{tableShade6}{HTML}{A1D99B}
\definecolor{tableShade7}{HTML}{D9F0D3}
\definecolor{tableShade1}{HTML}{FFEDA0}

\pagestyle{empty}
\renewcommand{\familydefault}{\sfdefault}
\renewcommand{\arraystretch}{1.25}
\usepackage{arydshln}
\newcolumntype{x}[1]{>{\raggedright}p{#1}}
\arrayrulecolor{tableShade3}
\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}
\rowcolors{1}{tableShade2}{white}\scriptsize
\newcommand{\CTPanel}[1]{%
\multicolumn{1}{>{\columncolor{white}}r|}{#1}}
\centering
\begin{longtable}{lp{0.3cm}!{\color{tableShade3}\vrule}
               p{0.3cm}!{\color{tableShade3}\vrule}
               p{0.3cm}!{\color{tableShade3}\vrule}
               p{0.3cm}!{\color{tableShade3}\vrule}
               p{0.3cm}!{\color{tableShade3}\vrule}
               p{0.3cm}!{\color{tableShade3}\vrule}
               p{0.3cm}!{\color{tableShade3}\vrule}
               p{0.3cm}!{\color{tableShade3}\vrule}
               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}
\endhead
\specialrule{0.01em}{0em}{0em}
\endfoot
\multicolumn{5}{l}{\textbf{The first subheading}}\\
\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}
\addlinespace[1.6em]
\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\\
\addlinespace[1em]
\multicolumn{6}{l}{AB: ABbreviation}\\
\end{longtable}
\end{document}

MWE of longtable with complicated legend

Final solution from D.Carlisle's accepted answer and comments below.

\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\\
\addlinespace[1em]
\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
\addlinespace[2pt]
\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!

5
  • 1
    Does it have to be a footnote (rather than just put it in the table foot, which is put on every page automatically)? Commented Mar 2, 2012 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
    – Ariel
    Commented Mar 2, 2012 at 21:24
  • 1
    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. Commented Mar 2, 2012 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?
    – Ariel
    Commented Mar 2, 2012 at 22:13
  • 1
    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 Commented Mar 2, 2012 at 22:19

1 Answer 1

7

enter image description here

\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}
\definecolor{tableShade2}{HTML}{F1F5FA}
\definecolor{tableShade}{HTML}{FAFAFD}
\definecolor{tableShade3}{HTML}{dddddd}
\definecolor{tableShade4}{HTML}{C2A5CF}
\definecolor{tableShade5}{HTML}{E7D4E8}
\definecolor{tableShade6}{HTML}{A1D99B}
\definecolor{tableShade7}{HTML}{D9F0D3}
\definecolor{tableShade1}{HTML}{FFEDA0}

\pagestyle{empty}
\renewcommand{\familydefault}{\sfdefault}
\renewcommand{\arraystretch}{1.25}
\usepackage{arydshln}
\newcolumntype{x}[1]{>{\raggedright}p{#1}}
\arrayrulecolor{tableShade3}
\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}
\rowcolors{1}{tableShade2}{white}\scriptsize
\newcommand{\CTPanel}[1]{%
\multicolumn{1}{>{\columncolor{white}}r|}{#1}}
\centering
\begin{longtable}{lp{0.3cm}!{\color{tableShade3}\vrule}
               p{0.3cm}!{\color{tableShade3}\vrule}
               p{0.3cm}!{\color{tableShade3}\vrule}
               p{0.3cm}!{\color{tableShade3}\vrule}
               p{0.3cm}!{\color{tableShade3}\vrule}
               p{0.3cm}!{\color{tableShade3}\vrule}
               p{0.3cm}!{\color{tableShade3}\vrule}
               p{0.3cm}!{\color{tableShade3}\vrule}
               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}
\endhead
\noalign{
\scriptsize
%Complicated legend begins
\begin{tabular}{llllll}
\addlinespace[1.6em]
\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\\
\addlinespace[1em]
\multicolumn{6}{l}{AB: ABbreviation}\\
\end{tabular}
}
\endfoot
\specialrule{0.01em}{0em}{0em}
\multicolumn{5}{l}{\textbf{The first subheading}}\\
\showrowcolors
some variable &+&+&-&+&+&-&-&-&-&-&+&+&-&-&+&+&-&-\\
some other variable &+&+&-&+&+&-&-&-&-&-&+&+&-&-&+&+&-&-\\
some other variable &+&+&-&+&+&-&-&-&-&-&+&+&-&-&+&+&-&-\\
\newpage
fourth variable &+&+&-&+&+&-&-&-&-&-&+&+&-&-&+&+&-&-\\
fifth variable &+&+&-&+&+&-&-&-&-&-&+&+&-&-&+&+&-&-\\
yet other variable &+&+&-&+&+&-&-&-&-&-&+&+&-&-&+&+&-&-\\
\end{longtable}
\end{document}
8
  • 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?
    – Ariel
    Commented Mar 2, 2012 at 22:30
  • 1
    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 Commented Mar 2, 2012 at 22:40
  • 1
    Sorry as I used \noalign not all LaTeX's state is restored, put \noalign{\raggedright \begin{tabular.... and the legend will go flush left. Commented Mar 2, 2012 at 22:58
  • 1
    I thought someone must have asked what is stretch (known as glue in TeX) this answers a related point tex.stackexchange.com/questions/21022/… Commented Mar 2, 2012 at 23:17
  • 1
    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} Commented Mar 2, 2012 at 23:18

You must log in to answer this question.

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