如何防止我的并排表格重叠?

如何防止我的并排表格重叠?

我有两个长表格,我想将它们并排显示。当我使用国家代码时,它们没问题,但当我想使用国家名称时,它们会变得太宽并且重叠。据我所知,页面上仍有足够的空间让表格并排显示而不会重叠。我不需要让表格看起来很漂亮(目前),我只需要它们易于阅读。

\documentclass[a4paper,12pt,times]{article}
\begin{document}    
\begin{table}
    \centering
    \caption{blablabla}
    \resizebox{0.6\textwidth}{!}{


     \begin{minipage}{.5\linewidth}
      \centering
    \begin{tabular}{lc|lc}
    \multicolumn{2}{l}{OLS} & \multicolumn{2}{r}{OLS}\tabularnewline
    \hline 
    \multicolumn{4}{c}{Negative}\tabularnewline
    \hline 
    A very very long country name & -0.00 & A very very long country name & -0.00\tabularnewline
    A very very long country name & -0.00 & A very very long country name & -0.00\tabularnewline

    \end{tabular}
    \end{minipage} 

    \hfill


    \begin{minipage}{.5\linewidth}
     \centering

    \begin{tabular}{lc|lc}
    \multicolumn{2}{l}{OLS} & \multicolumn{2}{r}{OLS}\tabularnewline
    \hline 
    \multicolumn{4}{c}{Negative}\tabularnewline
    \hline 
    A very very long country name & -1.00 & A very very long country name & -0.00\tabularnewline
    A very very long country name & -0.4 & A very very long country name & -0.01\tabularnewline

    \end{tabular}
    \end{minipage}} 
    \end{table}
\end{document}

答案1

表格重叠是因为您将它们压缩到固定宽度的迷你页面中。也许下面的代码片段可以帮助您找到更好的解决方案。但请注意,我必须猜测文档类和序言。

\documentclass[11pt,a4paper]{article}
\usepackage[left=2cm,right=2cm,top=2cm,bottom=2cm]{geometry}
\usepackage{graphicx}
\usepackage{array}
\begin{document}
Your original minipages were not wide enough to fit all the stuff you put there.
However, were also using a \texttt{tabular} environment, which prevented the
lines from breaking. Since you were using the \texttt{minipage} environment, I'm
wondering if you want the text to break. In that case consider
\begin{table}[h]
\centering
\caption{blablabla}
\begin{tabular}{cc}
 \begin{minipage}{.5\linewidth}
  \centering
\begin{tabular}{p{2.5cm}c|p{2.5cm}c}
\multicolumn{2}{l}{OLS} & \multicolumn{2}{r}{OLS}\tabularnewline
\hline 
\multicolumn{4}{c}{Negative}\tabularnewline
\hline 
A very very long country name & -0.00 & A very very long country name & -0.00\tabularnewline
A very very long country name & -0.00 & A very very long country name & -0.00\tabularnewline
\end{tabular}
\end{minipage} 
&
\begin{minipage}{.5\linewidth}
 \centering
\begin{tabular}{p{2.5cm}c|p{2.5cm}c}
\multicolumn{2}{l}{OLS} & \multicolumn{2}{r}{OLS}\tabularnewline
\hline 
\multicolumn{4}{c}{Negative}\tabularnewline
\hline 
A very very long country name & -1.00 & A very very long country name & -0.00\tabularnewline
A very very long country name & -0.4 & A very very long country name & -0.01\tabularnewline
\end{tabular}
\end{minipage}%} 
\end{tabular}
\end{table}

If you really want to use resizebox, recall first that
\verb|\resizebox{0.6\textwidth}{!}{stuff}| scales stuff to 0.6$\times$textwidth,
which is probably not what you wanted. I'm assuming you wanted to use
\verb|\scalebox| instead. A somewhat more appropriate usage of \verb|\resizebox|
yields
\begin{table}[h]
\centering
\caption{blablabla}
\resizebox{\textwidth}{!}{%
\begin{tabular}{m{16cm}m{16cm}}
 \begin{minipage}{.5\linewidth} 
  \centering
\begin{tabular}{p{6cm}c|p{6cm}c}
\multicolumn{2}{l}{OLS} & \multicolumn{2}{r}{OLS}\tabularnewline
\hline 
\multicolumn{4}{c}{Negative}\tabularnewline
\hline 
A very very long country name & -0.00 & A very very long country name & -0.00\tabularnewline
A very very long country name & -0.00 & A very very long country name & -0.00\tabularnewline
\end{tabular}
\end{minipage} 
& 
\begin{minipage}{.5\linewidth}
 \centering
\begin{tabular}{p{6cm}c|p{6cm}c}
\multicolumn{2}{l}{OLS} & \multicolumn{2}{r}{OLS}\tabularnewline
\hline 
\multicolumn{4}{c}{Negative}\tabularnewline
\hline 
A very very long country name & -1.00 & A very very long country name & -0.00\tabularnewline
A very very long country name & -0.4 & A very very long country name & -0.01\tabularnewline
\end{tabular}
\end{minipage}% 
\end{tabular}%
}
\end{table}

However, for the sake of readability I'd recommend not use this method. 

\end{document}

在此处输入图片描述

答案2

对于浮动中的两个平行表格,您不需要minipages。为了在单元格中获得更好的文本归档,我建议使用包RaggedRight中的命令ragged2e。字体也更小(但不小于\footnotesize)并且tabcolsep会有所帮助:

\documentclass[11pt,a4paper]{article}
\usepackage[left=2cm,right=2cm,top=2cm,bottom=2cm]{geometry}
\usepackage[skip=1ex]{caption}
\usepackage{ragged2e}
\usepackage{array}
\newcolumntype{R}[1]{>{\RaggedRight\hspace{0pt}}p{#1}}

\begin{document}
    \begin{table}[ht]
\caption{blablabla}
\centering
\renewcommand\arraystretch{1.2}
\setlength\tabcolsep{3pt}
\small
%
\begin{tabular}[t]{R{2.5cm}c|R{2.5cm}c}
\multicolumn{2}{l}{OLS} & \multicolumn{2}{r}{OLS}   \tabularnewline
    \hline
\multicolumn{4}{c}{Negative}\tabularnewline
    \hline
A very very long country name & -0.00 & A very very long country name & -0.00\tabularnewline
A very very long country name & -0.00 & A very very long country name & -0.00\tabularnewline
\end{tabular}\hfill
\begin{tabular}[t]{R{2.5cm}c|R{2.5cm}c}
\multicolumn{2}{l}{OLS} & \multicolumn{2}{r}{OLS}\tabularnewline
\hline
\multicolumn{4}{c}{Negative}\tabularnewline
\hline
A very very long country name & -1.00 & A very very long country name & -0.00\tabularnewline
A very very long country name & -0.4 & A very very long country name & -0.01\tabularnewline
\end{tabular}
    \end{table}
\end{document}

在此处输入图片描述

编辑:

如果你想把两张桌子粘在一起,那么在上面姆韦替换行

\end{tabular}\hfill
\begin{tabular}[t]{R{2.5cm}c|R{2.5cm}c}

和:

\end{tabular}%
\begin{tabular}[t]{R{2.5cm}c|R{2.5cm}c}

并使用\footnotesize字体大小你将获得:

在此处输入图片描述

不过,我想知道,为什么你不首先将这些表设置为一个?

相关内容