我正在尝试将我的表格草稿从 Word 迁移到 LaTeX。
以下 LaTeX 代码在“收入流”的单元格对齐方面存在问题。
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[]{multirow}
\begin{document}
\begin{table}[]
\centering
\caption{My caption}
\label{my-label}
\begin{tabular}{|l|l|l|l|l|l|}
\hline
\multirow{2}{*}{Key Partnerships} & Key Activities & \multicolumn{2}{l|}{\multirow{2}{*}{Value Proposition}} & Customer Relationships & \multirow{2}{*}{Customer Segments} \\ \cline{2-2} \cline{5-5}
& Key Resources & \multicolumn{2}{l|}{} & Channels & \\ \hline
\multicolumn{3}{|l|}{Cost Structure} & \multicolumn{3}{l|}{Revenue Streams} \\ \hline
\end{tabular}
\end{table}
\end{document}
建议如何创建正确的单元格对齐?
答案1
如果您想要拥有等宽单元格,最简单的解决方案是堆叠两个tabularx
总宽度相同的环境并调整两者之间的垂直间距。无论如何,您的表格无法适应正常大小的边距。
因此我提出了两种变体,都带有\small
字体大小。一种是所有单元格都为一行,但代价是扩大了表格的可打印区域。这是通过changepage
包及其adjustwidth
环境实现的。另一种是适合边距,但代价是一些换行符,并重新定义X
列类型以垂直对齐单元格内容。
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[showframe]{geometry}
\usepackage{multirow, tabularx, caption, makecell}
\usepackage{changepage}
\begin{document}
\begin{table}[!htb]
\begin{adjustwidth}{-1.2cm}{-1.2cm}
\centering\small\captionsetup{skip=6pt, font=small}
\setlength{\tabcolsep}{4pt}
\setlength{\extrarowheight}{2pt}
\caption{My caption}
\label{my-label}
\begin{tabularx}{\linewidth}{|*{6}{X|}}
\hline
\multirow{2}{*}{Key Partnerships} & Key Activities & \multicolumn{2}{l|}{\multirow{2}{*}{Value Proposition}} & Customer Relationships & \multirow{2}{*}{Customer Segments} \\ \cline{2-2} \cline{5-5}
& Key Resources & \multicolumn{2}{l|}{} & Channels & \\ \hline
\multicolumn{3}{|p{\dimexpr0.5\linewidth-2\tabcolsep-2\arrayrulewidth}|}{Cost Structure} & \multicolumn{3}{p{\dimexpr0.5\linewidth-2\tabcolsep-2\arrayrulewidth}|}{Revenue Streams} \\ \hline
\end{tabularx}\\[-0.5\extrarowheight]%\
\begin{tabularx}{\linewidth}{|*{2}{X|}}
Cost Structure & Revenue Streams \\ \hline
\end{tabularx}
\end{adjustwidth}
\end{table}
\begin{table}[!htb]
\renewcommand{\tabularxcolumn}[1]{>{\arraybackslash}m{#1}}
\centering\small\captionsetup{skip=6pt, font=small}
\setlength{\extrarowheight}{2pt}
\caption{My caption}
\label{my-label}
\begin{tabularx}{\linewidth}{|*{6}{X|}}
\hline
\multirow{2}{*}{Key Partnerships} & Key Activities & \multicolumn{2}{l|}{\multirow{2}{*}{Value Proposition}} & Customer \newline Relationships & \multirow{2}{*}{Customer Segments} \\ \cline{2-2} \cline{5-5}
& Key Resources & \multicolumn{2}{l|}{} & Channels & \\ \hline
\end{tabularx} \\ [-0.5\extrarowheight]%
\begin{tabularx}{\linewidth}{|*{2}{X|}}
Cost Structure & Revenue Streams \\ \hline
\end{tabularx}
\end{table}
\end{document}
答案2
可能是这样的:
\documentclass{article}
\usepackage{geometry}
\usepackage{multirow,tabularx}
\newcolumntype{L}{>{\raggedright\arraybackslash}X}
\usepackage[skip=1ex]{caption}
\begin{document}
\begin{table}
\centering
\renewcommand\arraystretch{1.2}
\caption{My caption}
\label{my-label}
\begin{tabularx}{\linewidth}{|*{6}{L|}}
\hline
\multirow{4}{=}{Key Partnerships} & Key Activities
& \multicolumn{2}{>{\hsize=\dimexpr2\hsize+2\tabcolsep}X|}{Value Proposition}
& Customer Relationships & \multirow{4}{=}{Customer Segments} \\
\cline{2-2} \cline{5-5}
& Key Resources
& \multicolumn{2}{>{\hsize=\dimexpr2\hsize+2\tabcolsep}X|}{}
& \multirow{2}{=}{Channels} & \\ \hline
\multicolumn{3}{|>{\hsize=\dimexpr3\hsize+4\tabcolsep}X|}{Cost Structure}
& \multicolumn{3}{>{\hsize=\dimexpr3\hsize+4\tabcolsep}X|}{Revenue Streams} \\ \hline
\end{tabularx}
\end{table}
\end{document}