49 Comments

  1. Thanks for this post. Could you also perhaps summarize the ways you can insert footnotes in the longtable environment? I have been trying to get the footnotes to display directly below where the table ends in the longtable environment but have not been very successful. They end up in the “footnote area”. Also footnotes in various parts of the long table, pre-table text, header text, table cell contents all seem to have different formats. It would be awesome if you could post a bit about it.

    • Hello! Sorry for the late response. After searching for quite some time, I found a package that allows placing footnotes in a longtable right below the table rather than at the bottom of the page. The package is called threeparttablex and is an extension of the threeparttable package. I changed the example from the documentation to make it a fully functional minimal example. Furthermore, I extended the code for automatic enumeration of the footnotes using a counter which is easily changed to roman, alphabetic, or numeric. Also, the counter is automatically reset when creating a new table.

      By moving the command \insertTableNotes you have the flexibility to place footnotes anywhere you want.

      \documentclass{article}
      \usepackage[referable]{threeparttablex}
      \usepackage{booktabs, longtable}
      \newcounter{tablenote}[table]
      \newcommand{\itemx}[1]{
      	\stepcounter{tablenote}
      	\item[\thetablenote]\label{#1}
      }
      \begin{document}
      \begin{ThreePartTable}
        \begin{TableNotes}
        \itemx{tn:a} test test test
        \itemx{tn:b} Referencing: see note \ref{tn:a}.
        \source Made up by daleif
        \end{TableNotes}
      \begin{longtable}{l l l}
        \caption{A long table}\\
        \toprule
        Coloum 1 & & Column 2\\
        \midrule
        \endhead
        \cmidrule{3-3}
        \multicolumn{3}{r}{\textit{continued}}
        \endfoot
        \bottomrule
        \insertTableNotes\\
        \endlastfoot
        AAAA\tnotex{tn:a} & & BBBB\\
      %  \newpage
        CC & & DD\tnotex{tn:b}\\
      \end{longtable}
      \end{ThreePartTable}
      \end{document}

      Best, Tom.

  2. Thanks mate! I spent countless hours trying to get this working before giving up while I was writing my thesis. Next time around, I know where to look. 🙂

    • Hey there,

      Either you pack everything into a floating environment like table which is not very nice. Or you may want to give the threeparttable package a try. Here is an example.

      \documentclass[11pt]{article}
      \usepackage{threeparttable}
      \begin{document}
      \begin{table}
      	\begin{threeparttable}[b]
      	\caption{Table caption.}
      		\begin{tabular}{|l|c|c|c|}
      			\hline
      			First & 42.5\tnote{1}&4.76&2.34\\
      			Second & 43.4&5.3&1.43\\
      			\hline
      		\end{tabular}
      		\begin{tablenotes}
      			\item [1] A table note ...
      		\end{tablenotes}
      	\end{threeparttable}
      \end{table}
      \end{document}

      The ctable package offers similar functionality.

      Best, Tom.

    • Thanks for your comment, Muhammad. I tried, but couldn’t make it work while writing the post. It was only when you wrote your comment, I search a bit more and figured that one has to place the \footnotetext outside the table environment. Here is an example for those who are interested:

      \begin{table}[ht]
      \begin{center}
      \begin{tabular}{|c|c|c|}
      \hline
      Title 1 & Title 2 & Title 3\\
      \hline
      1.234 & 5.687 & 2.234\footnotemark[1]\\
      1.234 & 5.687\footnotemark[2] & 2.234\\
      1.234 & 5.687 & 2.234\\
      \hline
      \end{tabular}
      \end{center}
      \end{table}
      \footnotetext[1]{First footnote at the bottom of the page.}
      \footnotetext[2]{Second footnote at the bottom of the page.}

      Thanks, Tom.

      • Bhawuk Garg

        Hi, I used this example of yours to insert the footnotes in the table but they appeared with the normal section text which is why I put the \footnotetext before \end{table} command and they appeared under the table. But the problem now is that they are centered and not right justified. Do you know how to right justify them?

      • Hi Bhawuk,

        Thanks for your question. Please provide a minimal working example to illustrate your problem.

        Best, Tom

    • Hey John,

      Thanks for your question. The footnote package allows placing footnotes in captions. However, in you will need to protect them. Otherwise, LaTeX will produce an error message.

      \caption{Figure caption\protect\footnote{Figure caption note.}}

      Cheers, Tom.

      • Ive been testing this morning, and it seems to break when using hyperref – specifically if using colorlinks=true.

        The following does not work

        \usepackage{footnote}
        \usepackage{hyperref}
        \hypersetup{
            colorlinks=true % false: boxed links; true: colored links
        }
        
      • Hi John,

        You are right, there is no simple solution for adding hyperlinks to footnote marks within floats. I found a similar question on Stack Exchange. The rather “creative” solution seems to work well, even with colorlinks=true.

        Btw, you can load the hyperref package with options, e.g.:

        \usepackage[colorlinks=true]{hyperref}

        Best, Tom.

  3. Linda

    Hi Tom!
    Could you give an example on how to write a line type in a figure caption? for example

    \caption{"dashed" refer to bla..bla..and  "dotdash" refer to bla..bla..}

    where the ” ” are examples of the line type

    Many thank in advance

    • Hey Linda,

      Easiest would be to just use the math-environement and write out the line, e.g.:

      \caption{$---$ refer to bla..bla..and $\cdot-\cdot-\cdot$ refer to bla..bla..}

      If you are looking for a more consistent way in terms of line length, try the dashrule package:

      \usepackage{dashrule}
      ...
      \caption{\hdashrule[0.5ex]{2cm}{1pt}{3mm} blabla; \hdashrule[0.5ex]{2cm}{1pt}{3mm 3pt 1pt 3pt} blabla}

      Best, Tom

  4. Hi there,

    many thx for this article. I’m writing my master theses and would like to have a footnote in my table.
    None of the above works though, and I really don’t know why. It is something with the other packages I asume, as your reduced example works great. Even with my own table.
    Before I try to fix that, maybe someone of you had the same experience and can help. I get a lot of the following errors:

    Latex Error: ./chapters/materials.tex:97 Extra }, or forgotten \endgroup.
    Latex Error: ./chapters/materials.tex:97 Missing } inserted.

    All in the same line. This is the line where my footnote statement is.
    Any ideas?

    best
    Pawel

    • Hi,
      sorry. My fault. I read about hyperref making it all go down the river, but forgot, that I also use that package… Have to look for something else.

      BTW: I used threeparttable package. It worked fine, but all footnotes which cause a line break in the footnote of the table cause a very strange behavior: The hole table ends up in the footnote area. Any ideas?

  5. Hi,

    everything is fine now. I installed the tablefootnote package. It works, although sometimes a footnote is on the wrong page. But I will deal with that in the end.

    best
    Pawel

  6. Laura

    I found it was better to keep in the table environment for consistency. With threeparttable, my caption would not align as other tables in my document. For simplicity, I used the \vline (in this instance to include borders) and \multicolumn macros to make it happen.

    \begin{table}[htbp]
    \caption{\label{tab:tab1}caption}
    \begin{tabular}{@{}ll|lll|l|}
    \hline
    \vline & heading& \multicolumn{3}{|c|}{heading, $unit$} & reference \\
    \cline{3-5}
    \vline & & low & mid & high & \\
    \hline
    \vline & entry$^a$  & l & m & h & citation \\
    \vline & entry$^b$ & l & m & h & citation \\
    \hline
    \multicolumn{6}{l}{$^a$ footnote} \\
    \multicolumn{6}{l}{$^b$ another footnote} \\
    \end{tabular}
    \end{table}
    
  7. stefanct

    i had (apparently) a very, very special case to solve. i wanted to fit a quite wide table in a landscape environment, about centered vertically and horizontally, use footnotes inside the table and xcolor, booktabs and slashbox (now diagbox) for formatting. i tried about every suggestion i could dig up, nothing worked perfectly. the biggest problem most of the time was positioning the table. it seems that most footnote-enhancing packages do some weird stuff related to the page space definitions… or so. other problems include longtable breaking z-order of xcolor/diagbox elements, caption going wild and probably half a dozen other things that i happily obliterated already 🙂

    my current solution is to use a minipage as was suggested here, thanks! (of course i have a with a much wider table, so this looks slightly insane as it is, because it is actually enlarged by the resizebox instead of made smaller, but you get the general idea 🙂
    maybe it helps someone… my almost minimal but fully working example:

    \documentclass[a4paper,11pt]{article}
    
    \usepackage{booktabs} % \toprule \midrule \bottomrule etc
    \usepackage[table]{xcolor}
    \definecolor{lightgray}{gray}{0.9}
    \usepackage{multirow}
    \usepackage{multicol}
    \usepackage{pdflscape}
    \usepackage{diagbox}
    
    \usepackage[pagebackref]{hyperref}
    \hypersetup{
    	citebordercolor=0 0 0,
    	filebordercolor=0 0 0,
    	linkbordercolor=0 0 0,
    	menubordercolor=0 0 0,
    	urlbordercolor=0 0 0,
    	pdfborderstyle={/S/U /W 0.2}, % stroke, underline, width 0.2
    }
    \usepackage[all]{hypcap} % fix caption anchors
    
    \renewcommand\footnoterule{} % remove line above footnotes
    
    \begin{document}
    
    \begin{landscape}
    \begin{table}
    \begin{minipage}{\linewidth}
    \hypersetup{pdfborderstyle={/W 0.2}} % disable borders temporarily because they would be drawn sideways, i.e. left of the text!
    \rowcolors{3}{lightgray}{}
    \resizebox{\linewidth}{!}{%
    \begin{tabular}{l cc}
    \toprule
    \multirow{2}{*}{\textbf{\diagbox{Device}{Bus}}} & \multicolumn{2}{|c}{\textbf{digital}} \\
     & \multicolumn{1}{|c}{{nom}} & max \\
    Battery~\footnote{oh yeah. a footnote.}		&	& 1\\
    % fun stuff to make alternatively colored rows not look too stupid with booktabs:
    \arrayrulecolor{lightgray}\specialrule{\aboverulesep}{0pt}{0pt}
    \arrayrulecolor{black}\specialrule{\lightrulewidth}{0pt}{\aboverulesep} % to center the vertical rules between this and the \bottomrule
    $\Sigma$	&\multicolumn{1}{|c}{0}	&1	 \\
    \bottomrule
    \end{tabular}
    }
    \caption[sigh]{works too, yay}
    \label{tbl}
    \end{minipage}
    \end{table}
    \end{landscape}
    
    \end{document}
  8. me

    note regarding when to load the package footnote:
    it seems as if xcolor is not the only package that interferes with footnote since i don’t use this package but got the error about missing braces “{“.
    loading footnnote last solved the problem

  9. Adam

    Nice post!
    However, your preferred method didn’t work perfectly for me. The footnotes end up on the page where the table environment is called in the latex-code, not where the table is placed in the final document.

    I need my table to be within a table environment. So I went for something similar to stefanct, using the same example as in the original post it should be something like this:

    \begin{table}[htbp]
      \caption{A table caption}
      \label{tab:stuff}
      \begin{minipage}{\textwidth}
        \vspace{3mm}
        \centering
        \begin{tabular}{|l|c|c|}
          \hline
          A & 1 & 2 \footnote{This is the first footnote.} \\
          \hline
          B & 2 & 1 \\
          \hline
          C & 3\footnote{This is the second footnote.} & 3 \\
          \hline
        \end{tabular}
      \end{minipage}
    \end{table}
    

    If I could, I would have wrapped everything in the table env in a minipage but I got errors for this even though the minipage was inside the table env.

    I usually place the caption above the table since this is more common in scientific papers. The \vspace is required since the default table environment in LaTeX is not designed for this layout and leaves no space here by default.

    A nice thing with this approach is that the footnote labels change to letters within the minipage so they are intuitively separated from the footnotes in the rest of the document.

    • Cool, thanks for the nicely formatted code. The only problem I see is the footnotes are aligned left whereas the tabular is centred. One could limit the width of the minipage environment, but that’s not a very elegant fix. Any idea?

      • Adam

        I’ve been thinking a bit about this now and can’t come up with a nice way to put footnotes under the table if the table does not span most of the page. I’d say that if there is enough horizontal space over, add an extra comment column rather than using footnotes or put several tables together. It’s not any fancier than manually setting the width of the minipage, just some other options to try out.

  10. Alexandre Benoy

    Thanks for this interesting post, even though I’m also used to define separately the footnotemark and footnotetext in case of a tabular environment (which in fact are the «bricks» upon which the \footnote{} command relies. That may be verified by looking at the definition of macro \footnote:

     
    \footnote:

    \@ifnextchar [\@xfootnote {\stepcounter \@mpfn \protected@xdef \@thefnmark {\thempfn }\@footnotemark \@footnotetext }

    One last detail, there is usually no need to specify a number for \footnotemark as it is automatically incremented. Then again by looking at the definition of this command/macro :

     
    \footnotemark:

    \@ifnextchar [\@xfootnotemark {\stepcounter {footnote}\protected@xdef \@thefnmark {\thefootnote }\@footnotemark }

    However it is of course necessary for \footnotetext as you wrote it.

    Alex.

  11. José Norberto Alba Juárez

    Tom, thank you so much, I tried different methods in order to solve this issue. Greetings from Mexico!

Leave a Reply