表格行数太长

表格行数太长

我使用以下代码创建了一个表:

\documentclass[12 pt,Times New Roman] {article}

\usepackage[utf8]{inputenc}
\usepackage { amsmath }
\usepackage{setspace}
\setstretch{1.5}

\usepackage{hyperref}
\usepackage[toc,page]{appendix}





\usepackage[a4paper,lmargin={2.5cm},rmargin={2.5cm},
tmargin={2.5cm},bmargin = {2.5cm}]{geometry}

\usepackage{caption}
\usepackage{booktabs}


\usepackage{fancyhdr}
\pagestyle{fancy}
\lhead{}
\chead{}
\rhead{Page \thepage}
\lfoot{}
\cfoot{}
\rfoot{}
\sloppy

\begin{document}
\begin{table}[h!]

\selectfont\centering

\caption[Caption]{Caption}
\begin{tabular}{p{1cm} p{1cm} p{1cm} p{1cm} p{1cm}  c c c c c}

\hline\hline


            &      title     &     title     &       title       &   title    \\
\hline
A           &       1.2      &       2.3     &       5.6\sym{**} &    4        \\
            &      (5.06)    &      (5.56)   &      (3.42)       &  (0.59)         \\
[1em]
B           &  -9.87\sym{*}  & -9.63\sym{*}  &      0.58         & 1.98\sym{***}\\
            &      (5.07)    &      (5.66)   &      (3.58)       &      (0.59)         \\

\hline
Adjusted \(R^{2}\)  &      ...        &       ...        &       ...         &       ...         \\
\hline\hline
\multicolumn{5}{l}{\footnotesize Robust standard errors in parentheses, \sym{*} \(p<0.10\), \sym{**} \(p<0.05\), \sym{***} \(p<0.01\)}\\
\multicolumn{5}{p{\ylength}}{\footnotesize note note note}\\
\\
\end{tabular}
\end{table}
\end{document}

问题是表格的宽度与文本的宽度相同,因此行的线条太长。如能得到任何帮助,我们将不胜感激。

答案1

考虑上述评论并猜测你的表格应该是什么样子:

在此处输入图片描述

\documentclass[12pt] {article}
\usepackage[a4paper,margin=2.5cm]{geometry}

\usepackage[utf8]{inputenc}
\usepackage {amsmath}
\usepackage{setspace}
\setstretch{1.5}

\usepackage{caption}
\usepackage{calc}
\usepackage{booktabs,tabularx}
\newlength\mylength
\setlength\mylength{0.5\textwidth}
\newcommand\mcp[1]{\multicolumn{5}{p{\mylength-2\tabcolsep}}{\footnotesize #1}}

\usepackage{showframe}
\renewcommand*\ShowFrameColor{\color{red}}


\begin{document}
\begin{table}[htb]
    \centering
    \setlength\tabcolsep{4pt}
\caption[Caption]{Caption}
    \label{my table}
\begin{tabularx}{\mylength}{l X X X X}
\toprule
        &   title   &   title   &   title   &   title       \\
\midrule
A       &   1.2     &   2.3     &   5.6{**} &   4           \\
        &   (5.06)  &   (5.56)  &   (3.42)  &  (0.59)       \\  [1em]
B       &  -9.87{*} &  -9.63{*} &   0.58    &  1.98{***}    \\
        &   (5.07)  &   (5.66)  &   (3.58)  &  (0.59)       \\
\midrule
Adjusted \(R^{2}\)  
        &   ...     &   ...     &   ...     &  ...          \\
\midrule
\mcp{Robust standard errors in parentheses, 
    {*} \(p<0.10\), {**} \(p<0.05\), {***} \(p<0.01\)}      \\
\mcp{note note note}                                        \\
\bottomrule
\end{tabularx}
    \end{table}
\end{document}

如果猜测错误,请编辑您的问题并澄清您的问题。

答案2

使用,您可以在表格下方添加表格注释,{NiceTabular}nicematrix宽度等于表格本身的宽度。

在下面的代码中,键tabularnote在表格注释区域中添加了一些数据。表格注释本身由内置命令插入\tabularnote。请注意,当多个表格注释具有完全相同的内容时,该内容只会在表格注释区域中插入一次。

\documentclass{article}
\usepackage{geometry}
\usepackage{caption}
\usepackage{nicematrix,enumitem,booktabs}

\ExplSyntaxOn
\NewDocumentCommand { \stars } { m } { \prg_replicate:nn { \value { #1 } } { $\star$ } }
\ExplSyntaxOff

\begin{document}

\begin{table}
\centering
\caption{Caption}
\NiceMatrixOptions{notes/para,notes/bottomrule,notes/style=\stars{#1}}
\begin{NiceTabular}{lllll}% <--- The % is mandatory
  [tabularnote = The robust standard errors in are presented in parentheses.]
\toprule
        &   title   &   title   &   title   &   title       \\
\midrule
A       &   1.2     &   2.3     &   5.6\tabularnote{$p<0.05$} &   4           \\
        &   (5.06)  &   (5.56)  &   (3.42)  &  (0.59)       \\[1em]
B       &  -9.87\tabularnote{$p<0.10$} &  -9.63\tabularnote{$p<0.10$} &   0.58    &  1.98\tabularnote{$p<0.01$}    \\
        &   (5.07)  &   (5.66)  &   (3.58)  &  (0.59)       \\
\midrule
Adjusted \(R^{2}\)  
        &   ...     &   ...     &   ...     &  ... \\
\midrule
\end{NiceTabular}
\end{table}

\end{document}

上述代码的输出

相关内容