latex - 重叠表格内容,如何包装单元格内容
问题描述
我正在尝试为表格编写代码,但某些列内容重叠。我在这里粘贴了完整的代码。请帮助我,因为我是乳胶新手。
\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}
解决方案
您正在使用允许自动换行符的表格的 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}
,你会得到一个更好的结果:
推荐阅读
- symfony - Symfony 4 - 安全性 - 从多个防火墙相互共享上下文
- python - 如何通过 Python 脚本使用 ./ 执行命令行程序?
- angular - 使用 Angular 和 Ionic 上传大文件
- javascript - data-toggle="tab" 和 data-toggle="collapse" 不起作用
- javascript - 从 Promise 访问数据
- html - HTML、CSS:在调整大小时通过过渡调整 IMG 大小
- c# - .NET Core 3.1 API 调用使用 Windows 身份验证保护的 .NET Framework WCF 服务(AD 组)
- python - 如何使用 tkinter 在 python 中选择多个文件或整个文件夹(显示它包含的所有文件的名称)?
- python - 用于抓取多个页面标题的 Python 问题
- python - 搜索栏带来空白结果页面