使文本适合表格边框

使文本适合表格边框

我试图让这个表格整洁美观,但我无法让变量名称适合表格本身的长度。代码如下:

\documentclass[12pt]{article}
\usepackage{booktabs}
\usepackage{rotating}
\usepackage{adjustbox}
\usepackage{graphicx}
\usepackage{tabularx}
\begin{document}

% -------Begin LaTeX code -------%

{
%\begin{adjustbox}

\begin{table}[htbp]\centering
 \caption{GMM Estimates of First-Differenced Investment Equations
\label{GMM Estimates of First-Differenced Investment Equations}}


\begin{adjustbox}{width=1\textwidth}

\begin{tabular}{p{2cm} p{1cm} p{1cm}p{2cm}p{2cm}p{1cm}p{1cm}p{1cm}}\hline\hline 
\multicolumn{1}{c}
{\textbf{Variable}}
 & {\textbf{Full Sample (1)}}  & \textbf{{Rated Sample (2)}} & {\textbf{Unrated Sample (3)}} & {\textbf{Variable}}
 & {\textbf{Full Sample (4)}}  & \textbf{{Rated Sample (5)}} & {\textbf{Unrated Sample (6)}}\\ \hline

    &   &   &   &   &   &   &\\

\hline
\multicolumn{1}{c}
{\textbf{Variable}}
 & {\textbf{Full Sample (7)}}  & \textbf{{Rated Sample (8)}} & {\textbf{Unrated Sample (9)}} & {\textbf{Variable}}
 & {\textbf{Full Sample (10)}}  & \textbf{{Rated Sample (11)}} & {\textbf{Unrated Sample(12)}} \\
\hline
&   &   &   &   &   &   &\\

\hline
\end{tabular}
\end{adjustbox}

\end{table}

}


%------- End LaTeX code -------%
%\end{adjustbox}
\end{document}

您能否帮助我了解我遗漏了什么,导致我无法使文本很好地适应?非常感谢您的时间和帮助!

答案1

你可以尝试这样的方法。我稍微简化了这个例子以减少干扰:

\documentclass[12pt]{article}
\usepackage{booktabs}
\usepackage{tabularx}

\begin{document}

\begin{table}[htbp]\centering
  \caption{GMM Estimates of First-Differenced Investment Equations%
    \label{GMM Estimates of First-Differenced Investment Equations}}
  \small
  \begin{tabularx}{\textwidth}{*{8}{X}}\toprule
    \centering\sffamily Variable
     & \sffamily Full Sample (1)  & \sffamily Rated Sample (2) & \sffamily Unrated Sample (3) & \sffamily Variable
     & \sffamily Full Sample (4)  & \sffamily Rated Sample (5) & \sffamily Unrated Sample (6)\\\midrule

    \centering\sffamily Variable
     & \sffamily Full Sample (7)  & \sffamily Rated Sample (8) & \sffamily Unrated Sample (9) & \sffamily Variable
     & \sffamily Full Sample (10)  & \sffamily Rated Sample (11) & \sffamily Unrated Sample (12) \\\bottomrule
  \end{tabularx}

\end{table}

\end{document}

表格

答案2

理想情况下,此表的字体大小应该较小,但我将允许其他人提出如何实现这一点的建议。我在这里所做的只是\-在有问题的列中引入连字符点 ( ),以允许它在列边界内连字符。

\documentclass[12pt]{article}
\usepackage{booktabs}
\usepackage{rotating}
\usepackage{adjustbox}
\usepackage{graphicx}
\usepackage{tabularx}
\begin{document}

% -------Begin LaTeX code -------%

{
%\begin{adjustbox}

\begin{table}[htbp]\centering
 \caption{GMM Estimates of First-Differenced Investment Equations
\label{GMM Estimates of First-Differenced Investment Equations}}
\begin{adjustbox}{width=1\textwidth}


\begin{tabular}{p{2cm} p{1cm} p{1cm}p{2cm}p{2cm}p{1cm}p{1cm}p{1cm}}\hline\hline 
\multicolumn{1}{c}
{\textbf{Variable}}
 & {\textbf{Full Sample (1)}}  & \textbf{{Rated Sample (2)}} & {\textbf{Unrated Sample (3)}} & {\textbf{Variable}}
 & {\textbf{Full Sample (4)}}  & \textbf{{Rated Sample (5)}} & {\textbf{Un\-rated Sam\-ple (6)}}\\ \hline

    &   &   &   &   &   &   &\\

\hline
\multicolumn{1}{c}
{\textbf{Variable}}
 & {\textbf{Full Sample (7)}}  & \textbf{{Rated Sample (8)}} & {\textbf{Unrated Sample (9)}} & {\textbf{Variable}}
 & {\textbf{Full Sample (10)}}  & \textbf{{Rated Sample (11)}} & {\textbf{Un\-rated Sam\-ple (12)}} \\
\hline
&   &   &   &   &   &   &\\

\hline
\end{tabular}
\end{adjustbox}

\end{table}

}


%------- End LaTeX code -------%
%\end{adjustbox}
\end{document}

在此处输入图片描述

答案3

调整部分列宽,将值\tabcolsep(决定列间空白量)减少 25%,删除第一列左侧和最后一列右侧的空白,并去掉一些不需要的双花括号,这样表格就可以适合文本块,而无需使用\adjustbox或减小字体大小:

在此处输入图片描述

\documentclass[12pt]{article}
\usepackage{booktabs}
\begin{document}
\begin{table}
\setlength\tabcolsep{4.5pt} % default value: 6pt
\centering
\caption{GMM Estimates of First-Differenced Investment Equations}
\label{tab:GMMEstimates}    
\smallskip % provide a bit of separation between caption and tabular material

\begin{tabular}{@{} p{1.75cm}p{1cm}p{1.1cm}p{2cm} p{1.75cm}p{1cm}p{1.1cm}p{1.75cm} @{}}
\toprule 
\textbf{Variable} & \textbf{Full Sample (1)}  
& \textbf{Rated Sample (2)} & \textbf{Unrated Sample (3)} 
& \textbf{Variable} & \textbf{Full Sample (4)}  
& \textbf{Rated Sample (5)} & \textbf{Unrated Sample (6)}\\ 
\midrule
\\
\toprule
\textbf{Variable} & \textbf{Full Sample (7)}  
& \textbf{Rated Sample (8)} & \textbf{Unrated Sample (9)} 
& \textbf{Variable} & \textbf{Full Sample (10)}  
& \textbf{Rated Sample (11)} & \textbf{Unrated Sample (12)} \\
\midrule
\end{tabular}
\end{table}
\end{document}

相关内容