如何為這個表添加標題和註解?

如何為這個表添加標題和註解?

我正在嘗試向下表添加標題和註釋:

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

這是我的嘗試:

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

然而,這並不能提供我想要得到的東西。此外,我希望桌子居中。

誰能幫我?

多謝!

答案1

threeparttable 我將說明普通表格和threeparttablex用於跨頁表格的語法之間的差異。我添加了一些改進\extrarowheight和 規則,從中booktabs引入了不同厚度的規則,並為這些規則添加了一些垂直填充:

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

在此輸入影像描述

答案2

由於(a)您沒有使用任何\tnote指令,(b)標題很短,並且(c)主要但迄今為止尚未解決的格式化任務之一是防止表格材料超出\textwidth,我認為使用threeparttable環境非常有用。

只需使用一個tabularx環境來允許標題單元格中換行,並將較長的圖例排版為tabularx環境下方的普通文字。

在此輸入影像描述

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

答案3

如果您的表格確實很長,必須分成兩頁,那麼您可以考慮使用xltabular, [referable]{threeparttablex}and makecell(在單元格內容周圍添加更多垂直空間):

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

兩次編譯後表為:

在此輸入影像描述

在此輸入影像描述

附錄: 考慮到@烏娜評論,這是表格的版本,表格第一部分的頂部帶有註釋:

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

在此輸入影像描述 在此輸入影像描述

相關內容