Como adicionar um título e uma nota a esta tabela?

Como adicionar um título e uma nota a esta tabela?

Estou tentando adicionar um título e uma nota à seguinte tabela:

\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}

Esta é minha tentativa:

\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}

Isso, no entanto, não consegue entregar o que eu gostaria de obter. Além disso, gostaria que a mesa ficasse centralizada.

Alguém pode me ajudar?

Muito obrigado!

Responder1

Ilustrarei a diferença de sintaxe entre threeparttable tabulares comuns e threeparttablex, para ser usado em tabelas que quebram páginas. Eu adicionei algumas melhorias nas \extrarowheightregras e booktabsintroduzi regras com espessuras variadas e adicionei algum preenchimento vertical para essas regras:

\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}

insira a descrição da imagem aqui

Responder2

Como (a) você não está usando nenhuma \tnotediretiva, (b) a legenda é bem curta e (c) uma das principais tarefas de formatação, mas até agora não abordadas, é evitar que o material tabular exceda \textwidth, não acho que usar um threeparttableambiente é muito útil.

Basta empregar um tabularxambiente para permitir quebras de linha nas células do cabeçalho e digitar a legenda longa como texto comum abaixo do tabularxambiente.

insira a descrição da imagem aqui

\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}

Responder3

se sua tabela for realmente tão longa que precise ser dividida entre duas páginas, considere usar xltabular, [referable]{threeparttablex}e makecell(para adicionar mais espaço vertical ao redor do conteúdo das células):

\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}

Depois de duas compilações a tabela fica:

insira a descrição da imagem aqui

insira a descrição da imagem aqui

Termo aditivo: Considerando@Unacomente, aqui está a versão da sua tabela com notas no topo da primeira parte da tabela:

\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}

insira a descrição da imagem aqui insira a descrição da imagem aqui

informação relacionada