首页 > 解决方案 > 重叠表格内容,如何包装单元格内容

问题描述

我正在尝试为表格编写代码,但某些列内容重叠。我在这里粘贴了完整的代码。请帮助我,因为我是乳胶新手。

\documentclass[12pt,letterpaper,thmsa]{article}

\usepackage{multirow}





\begin{document}




\begin{table}
 \caption{Example to compute the required figures}
  \begin{center}
    \begin{tabular}{|p{0.05\linewidth}|p{0.05\linewidth}|p{0.05\linewidth}|p{0.05\linewidth}|p{0.05\linewidth}|p{0.05\linewidth}|p{0.05\linewidth}|p{0.05\linewidth}|p{0.05\linewidth}|p{0.05\linewidth}|}
    \hline
    % after \\: \hline or \cline{col1-col2} \cline{col3-col4} ...
      \multirow{2}{*}{Current Phase}  & \multicolumn{2}{c|}{First variable} &    \multicolumn{2}{c|}{Second Variable} & DIfference in Phase & Total of the first variable & Growth inforst variable &   \multicolumn{2}{c|}{CHange in second variable}\\
\cline{2-5}
    & Old & New& $Lab$ &    $Lab$   &&&&&\\
 \hline
$TP0$ & 200 &    400  & 10&    0&   &  10& NA& Old&    New\\
\hline
$TP1$& 400& 400  &10& 0&  $TP0$ to $TP1$& 200& 10& 0&  0\\
\hline
$TP2$ & 200& 400& 0&  10&  $TP0$ to $TP2$& 200& 10& -10& 10\\
\hline
  \end{tabular}
  \end{center}
 \label{Toy_exp}
\end{table}

\end{document} 

标签: latex

解决方案


您正在使用允许自动换行符的表格的 p 列,但如果您继续使用,\multicolumn{2}{c}{...}您将使用没有换行符的居中单元格覆盖它。

如果你使用固定宽度的列,你会得到换行符(虽然不是很漂亮,因为你的页面对于这个表格布局来说太小了)。

\documentclass[12pt,letterpaper,thmsa]{article}

\usepackage{multirow}

\usepackage{caption}

\begin{document}




\begin{table}
 \caption{Toy example to depict the STI calculation}
\centering
    \begin{tabular}{|p{0.1\linewidth}|p{0.05\linewidth}|p{0.05\linewidth}|p{0.05\linewidth}|p{0.05\linewidth}|p{0.1\linewidth}|p{0.1\linewidth}|p{0.1\linewidth}|p{0.05\linewidth}|p{0.05\linewidth}|}
    \hline
    % after \\: \hline or \cline{col1-col2} \cline{col3-col4} ...
      \multirow{2}{=}{Time Period}  & \multicolumn{2}{p{0.1\linewidth}|}{Labour Productivity} &    \multicolumn{2}{p{0.1\linewidth}|}{Labour force} & Change in Period &  Aggregate Productivity & Growth in Productivity &   \multicolumn{2}{p{0.1\linewidth}|}{Change in Labour Force}\\
\cline{2-5}
    & Trad. & Mod. & $L_t$ &    $L_m$   &&&&&\\
 \hline
$T_0$ & 10 &    20  & 1&    0&   &  10& NA& Trad.&    Mod.\\
\hline
$T_1$&  20& 20  &1& 0&  $T_0$ to $T_1$& 20& 10& 0&  0\\
\hline
$T_2$ & 10& 20& 0&  1&  $T_0$ to $T_2$& 20& 10& -1& 1\\
\hline
  \end{tabular}
 \label{Toy_exp}
\end{table}

\end{document} 

在此处输入图像描述

如果你给你的桌子足够的呼吸空间,例如通过添加\usepackage[landscape]{geometry},你会得到一个更好的结果:

在此处输入图像描述


推荐阅读