![多行多列的表格](https://linux22.com/image/313889/%E5%A4%9A%E8%A1%8C%E5%A4%9A%E5%88%97%E7%9A%84%E8%A1%A8%E6%A0%BC.png)
我想用 LaTeX 创建一个\multirow
表格\multicolumn
。
我尝试了一些帖子1,2,3创建我的表格,但是因为我无法创建我的表格。
请帮我提供下表的 LaTeX 代码。
到目前为止我写了这段代码:
\begin{tabular}{ |p{5cm}|p{4cm}|p{3cm}|p{3cm}| }
\hline
\multicolumn{4}{|c|}{\textbf{Crop field location info}} \\
\hline
\textbf{District name} & \textbf{Tehsil name} & \textbf{UC name}
& \textbf{UC \#}\\ & & &\\
\hline
\multicolumn{4}{|c|}{\textbf{Farmer's info}} \\
\hline
\textbf{Farmer name} & \textbf{Farmer contact \#}
& \multicolumn{2}{ |c| }{\textbf{Farmer's land holding (acres)}} \\
& & \multicolumn{2}{ |c| }{} \\
\hline
\textbf{Item} & \textbf{Unit} & \textbf{Rate/Unit} & \textbf{Total Cost}\\
\hline
\end{tabular}
答案1
您为准备 MWE 所做的努力太少了 :_),所以我从您的图片中只写下了表格的开头。对于您的表格,您不需要多行单元格。一个简单的解决方案如下:
\documentclass{article}
%just for show only a table
\usepackage[active,tightpage]{preview}
\PreviewEnvironment{tabular}
\setlength\PreviewBorder{1em}
\begin{document}
\sffamily
\small
\renewcommand{\arraystretch}{1.2}
\begin{tabular}{|p{0.4\textwidth} % determine column width to your wish
|p{0.1\textwidth}
|p{0.15\textwidth}
|p{0.15\textwidth}
|p{0.20\textwidth}|
}
\hline
\multicolumn{5}{|c|}{Crop field location info}\\
\hline
District name &
\multicolumn{2}{|c|}{Tehsil name}
& UC name & UC \# \\[2em]
\hline
\multicolumn{5}{|c|}{Farmer's info} \\
\hline
Farmer name &
\multicolumn{2}{|c|}{Farmer contract \#}
&
\multicolumn{2}{|c|}{Farmer's Land holdings (acres)} \\[2em]
\hline
Item & Unit & Quality & Rate/Unit & All cost \\
\hline
% repeat regarding to your table contents ...
\multicolumn{1}{|c}{}
&
\multicolumn{4}{ c|}{Land preparation cost} \\
\hline
Ploughing \& planking (Bullocks)
& Rs./Hr & & & \\
\hline
etc & & & & \\
\hline
\end{tabular}
\end{document}
答案2
您可以使用该\multicol
包来完成此任务。这里我有前几行的示例:
\documentclass{article}
\usepackage{multicol}
\begin{document}
\begin{tabular}{ |p{5cm}|p{2cm}|p{2cm}|p{3cm}|p{3cm}| }
\hline
\multicolumn{5}{|c|}{\textbf{Crop field location info}} \\
\hline
\textbf{District name} & \multicolumn{2}{ |c| }{\textbf{Tehsil name}}
& \textbf{UC name} & \textbf{UC \#}\\
& \multicolumn{2}{ |c| }{} & &\\
\hline
\multicolumn{5}{|c|}{\textbf{Farmer's info}} \\
\hline
\textbf{Farmer name} & \multicolumn{2}{|c|}{\textbf{Farmer contact \#}}
& \multicolumn{2}{ |c| }{\textbf{Farmer's land holding (acres)}} \\
& \multicolumn{2}{ |c| }{} & \multicolumn{2}{ |c| }{} \\
\hline
\textbf{Item} & \textbf{Unit} & \textbf{Quantity} & \textbf{Rate/Unit} & \textbf{Total Cost}\\
\hline
& \multicolumn{4}{ c| }{\textbf{Land preparation cost}} \\
\hline
Ploughing \& planking (Bullocks) & Rs./hr & & & \\
\hline
Leveling (Bullocks) & Rs./hr & & & \\
\hline
\end{tabular}
\end{document}
有关正确使用的更多信息,请访问latex_tables