2

I am trying to add a title and a note to the following table:

\documentclass{article}

\usepackage{longtable,pdflscape}

\begin{document}

\begin{longtable}[{l*{6}{c}r}]

    \hline 
     & Gov. Rev & Gov. Exp & Interest Rate & DFPA & GDP & Inflation \\ 
    \hline 
\endhead

    \textit{Business Cycle shock} & + &  & & & + & + \\
    \textit{Monetary Policy shock}  &  & & $-$ & & + & + \\
    \textit{DFPA shock}      & + & $-$ & & $-$ & &  \\
    

\end{longtable}

\end{document}

This is my attempt:

\documentclass{article}
\usepackage{booktabs, caption}
\usepackage{float}
\usepackage[flushleft]{threeparttable}


\begin{document}


\begin{longtable}[{l*{6}{c}r}]
\centering
\begin{threeparttable}
\caption{Identifying Sign Restrictions}
    \hline 
     & Gov. Rev & Gov. Exp & Interest Rate & DFPA & GDP & Inflation \\ 
    \hline 
\endhead

    \textit{Business Cycle shock} & + &  & & & + & + \\
    \textit{Monetary Policy shock}  &  & & $-$ & & + & + \\
    \textit{DFPA shock}      & + & $-$ & & $-$ & &  \\
    
\begin{tablenotes}
\small
\item \textit{Note}: This table shows the sign restrictions on the impulse responses for each identified shock. A \enquote{$+$} means that the impulse response of the variable in question is restricted to be positive for six months following the shock, including the month of impact. Likewise, a \enquote{$-$} indicates a negative response. A blank entry indicates that no restrictions have been imposed.
\end{tablenotes}
\end{threeparttable}    
\end{longtable}

\end{document}

This, however, fails to deliver what I would like to get. Besides, I would like the table to be centred.

Can anyone help me?

Thanks a lot!

  • 1
    centering is not an environment. – Bernard Sep 16 at 14:59
  • sorry, a typo, just edited – Rollo99 Sep 16 at 15:03
  • 3
    threeparttable can't work with longtable. You have to use the threeparttablex` package. The syntax is slightly different. – Bernard Sep 16 at 15:20
  • it doesn't need to be longtable. It can be a simple table as well with the same shape – Rollo99 Sep 16 at 15:34
  • 1
    If you don't use the longtable or xltabularx environments, you can use the plain threeparttable – Bernard Sep 16 at 16:28
3

I'll illustrate the difference of syntax between threeparttable for ordinary tabulars and threeparttablex, to be used for tables that break across pages. I added some improvements with \extrarowheight and the rules from booktabs which introduces rules with varying thickness and adds some vertical padding for these rules:

\documentclass{article}
\usepackage{array, booktabs, caption, longtable, booktabs, makecell}
\usepackage{csquotes}
\usepackage{float}
\usepackage[flushleft]{threeparttablex}

\begin{document}

\setlength{\extrarowheight}{2pt}

\begin{ThreePartTable} \centering
\begin{TableNotes}
\small
\item\hskip -\fontdimen2\font\textit{Note}: This table shows the sign restrictions on the impulse responses for each identified shock. A \enquote{$+$} means that the impulse response of the variable in question is restricted to be positive for six months following the shock, including the month of impact. Likewise, a \enquote{$-$} indicates a negative response. A blank entry indicates that no restrictions have been imposed.
\end{TableNotes}
\begin{longtable}{l*{6}{c}r}
\caption{Identifying Sign Restrictions}\\
    \toprule
     & \makecell{Gov.\\ Rev} & \makecell{Gov.\\Exp} & \makecell{Interest\\ Rate} & DFPA & GDP & Inflation \\
    \midrule
\endfirsthead
\midrule
     & \makecell{Gov.\\ Rev} & \makecell{Gov.\\ Exp} &\makecell{Interest\\ Rate} & DFPA & GDP & Inflation \\
    \midrule
\endhead
\bottomrule
\insertTableNotes
\endlastfoot
    \textit{Business Cycle shock} & + & & & & + & + \\
    \textit{Monetary Policy shock} & & & $-$ & & + & + \\
    \textit{DFPA shock} & + & $-$ & & $-$ & & \\
\end{longtable}
\end{ThreePartTable}
\begin{table}[!h]
\begin{threeparttable}
\centering
\caption{Identifying Sign Restrictions}
\begin{tabular}{@{}l*{6}{c}@{}}
    \toprule
     & \makecell{Gov.\\ Rev} & \makecell{Gov.\\ Exp} & \makecell{Interest\\ Rate} & DFPA & GDP & Inflation \\
    \midrule
    \textit{Business Cycle shock} & + & & & & + & + \\
    \textit{Monetary Policy shock} & & & $-$ & & + & + \\
    \textit{DFPA shock} & + & $-$ & & $-$ & & \\
\bottomrule
\end{tabular}
\begin{tablenotes}
\small
\item\hskip -\fontdimen2\font\textit{Note}: This table shows the sign restrictions on the impulse responses for each identified shock. A \enquote{$+$} means that the impulse response of the variable in question is restricted to be positive for six months following the shock, including the month of impact. Likewise, a \enquote{$-$} indicates a negative response. A blank entry indicates that no restrictions have been imposed.
\end{tablenotes}
\end{threeparttable}
\end{table}

\end{document}

enter image description here

| improve this answer | |
  • The words in the header row are spaced rather closely. Maybe introduce line breaks in the labels of the first three data columns? – Mico Sep 17 at 9:22
  • @Mico: You're right. I mainly focused on the syntax differences of both packages and overlooked this aspect of things. Thanks for the suggestion! – Bernard Sep 17 at 11:41
3

Since (a) you're not using any \tnote directives, (b) the caption is quite short, and (c) one of the main but so-far unaddressed formatting tasks is to keep the tabular material from exceeding \textwidth, I don't think that using a threeparttable environment is all that useful.

Just employ a tabularx environment to allow line breaks in the header cells and typeset the longish legend as ordinary text below the tabularx environment.

enter image description here

\documentclass{article}
\usepackage{booktabs,tabularx,ragged2e}
\newcolumntype{C}{>{\Centering\hspace{0pt}}X}
\usepackage[skip=0.333\baselineskip]{caption}
\usepackage[english=american]{csquotes} % select suitable language options

\begin{document}
\begin{table}
\setlength\tabcolsep{3.5pt} % default: 6pt
\caption{Identifying Sign Restrictions}
\begin{tabularx}{\textwidth}{@{} >{\itshape}l *{6}{C} @{}}
\toprule 
& Gov. Rev & Gov. Exp & Interest Rate & DFPA & GDP & Inflation \\ 
\midrule

Business Cycle shock  &$+$&   &   &   &$+$&$+$ \\
Monetary Policy shock &   &   &$-$&   &$+$&$+$ \\
DFPA shock            &$+$&$-$&   &$-$&   &    \\
\bottomrule
\end{tabularx}
    
\medskip
\textit{Note}: This table shows the sign restrictions on the impulse responses for each identified shock. A~\enquote{$+$} means that the impulse response of the variable in question is restricted to be positive for six months following the shock, including the month of impact. Likewise, a~\enquote{$-$} indicates a negative response. A blank entry indicates that no restrictions have been imposed.
\end{table}

\end{document}
| improve this answer | |
1

if your table is really so long that it has to be split between two pages, then you may consider to use xltabular, [referable]{threeparttablex} and makecell (for adding more vertical space around cells contents):

\documentclass{article}
\usepackage[skip=1ex]{caption}
\usepackage{booktabs, makecell, xltabular}
\newcolumntype{C}{>{\centering\arraybackslash}X}
\usepackage[referable, flushleft]{threeparttablex}
\usepackage{csquotes}

\usepackage{lipsum}


\begin{document}
\lipsum[1-4]
\begin{ThreePartTable} 
    \setlength\tabcolsep{3pt} % default: 6pt
    \setcellgapes{2pt}
    \makegapedcells
    \begin{TableNotes}\small
\note{This table shows the sign restrictions on the impulse responses for each identified shock. A \enquote{$+$} means that the impulse response of the variable in question is restricted to be positive for six months following the shock, including the month of impact. Likewise, a \enquote{$-$} indicates a negative response. A blank entry indicates that no restrictions have been imposed.}
    \end{TableNotes}
\begin{xltabular}{\linewidth}{@{}>{\itshape}l *{6}{C} @{}}
\caption{Identifying Sign Restrictions}
\label{tab:lonmngtable}                             \\
    \toprule
     & Gov. Rev 
        & Gov. Exp 
            & Interest Rate 
                & DFPA & GDP & Infla\-tion            \\
    \midrule
\endfirsthead
\caption[]{Identifying Sign Restrictions (cont.)}   \\
    \toprule
     & \makecell{Gov.\\ Rev}
        & \makecell{Gov.\\Exp}
            & \makecell{Interest\\ Rate}
                & DFPA & GDP & Inflation \\
    \midrule
\endhead
    \bottomrule
    \multicolumn{7}{r}{\footnotesize\textit{Continue on the next page}}
\endfoot
    \bottomrule
    \insertTableNotes
\endlastfoot
Business Cycle shock    & + & &     &       & + & + \\
Monetary Policy shock   &   & & $-$ &       & + & + \\
DFPA shock              & + & $-$ & & $-$   &   &   \\
xxxx shock              & + & $-$ & & $-$   &   &   \\
xxxx shock              & + & $-$ & & $-$   &   &   \\
\end{xltabular}
    \end{ThreePartTable}
\end{document}

After two compilation the table is:

enter image description here

enter image description here

Addendum: Considering @Una comment, here is version of your table with notes on the top of the first part of table:

\usepackage[skip=1ex]{caption}
\usepackage{booktabs, makecell, xltabular}
\newcolumntype{C}{>{\centering\arraybackslash}X}
\usepackage[referable, flushleft]{threeparttablex}
\usepackage{csquotes}

\usepackage{lipsum}


\begin{document}
\lipsum[1-3]
\begin{ThreePartTable} 
    \setlength\tabcolsep{3pt} % default: 6pt
    \setcellgapes{2pt}
    \makegapedcells
    \begin{TableNotes}\small
\note{This table shows the sign restrictions on the impulse responses for each identified shock. A \enquote{$+$} means that the impulse response of the variable in question is restricted to be positive for six months following the shock, including the month of impact. Likewise, a \enquote{$-$} indicates a negative response. A blank entry indicates that no restrictions have been imposed.}
    \end{TableNotes}
\begin{xltabular}{\linewidth}{@{}>{\itshape}l *{6}{C} @{}}
\caption{Identifying Sign Restrictions}
\label{tab:lonmngtable}                             \\                           
    \insertTableNotes                               \\
    
    \toprule
     & Gov. Rev 
        & Gov. Exp 
            & Interest Rate 
                & DFPA & GDP & Infla\-tion            \\
    \midrule
\endfirsthead
\caption[]{Identifying Sign Restrictions (cont.)}   \\
    \toprule
     & \makecell{Gov.\\ Rev}
        & \makecell{Gov.\\Exp}
            & \makecell{Interest\\ Rate}
                & DFPA & GDP & Inflation \\
    \midrule
\endhead
    \bottomrule
    \multicolumn{7}{r}{\footnotesize\textit{Continue on the next page}}
\endfoot
    \bottomrule
\endlastfoot
Business Cycle shock    & + & &     &       & + & + \\
Monetary Policy shock   &   & & $-$ &       & + & + \\
DFPA shock              & + & $-$ & & $-$   &   &   \\
xxxx shock              & + & $-$ & & $-$   &   &   \\
xxxx shock              & + & $-$ & & $-$   &   &   \\
\end{xltabular}
    \end{ThreePartTable}
\end{document}

enter image description here enter image description here

| improve this answer | |
  • 1
    If the table runs to multiple pages you may want to put the note at the top of the table, either on the first page or on every page. – Una Sep 17 at 14:31
  • 1
    @Una, this can be simply dan with moving \insertTableNotes in desired position, for example into definition for the firsthead, or head or in the foot. So far there is no respoce of OP what (s) like to have.To mee is sensible to put in the firsthead, i.e. on the top of the firsthead (mmediately after caption)`. – Zarko Sep 17 at 14:57
  • 1
    did you perhaps mean to make a followup comment to the OP about my style advice? – Una Sep 17 at 15:50
  • 1
    @Una, no before (s)he respond to my answer. So far above comments should suffice. – Zarko Sep 17 at 16:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.