![行与行之间的列数不同](https://linux22.com/image/278658/%E8%A1%8C%E4%B8%8E%E8%A1%8C%E4%B9%8B%E9%97%B4%E7%9A%84%E5%88%97%E6%95%B0%E4%B8%8D%E5%90%8C.png)
我想创建一个这样的表格:
| H1 | h2 | <--- is centered vertically
| T1 | |
| T1 | text | text | text |
| T1 | text | text |
| T1 | text |text | text|text |
我该怎么做?主要问题出在第 2 行。
示例可行,但 5 列行未正确居中
\begin{table}[!hbt]
\centering
\caption{caption} \label{tab:table}
\begin{tabular}{c c c c c c c c c c c c c}
\toprule
xxxxxxx & \multicolumn{12}{c}{yyyyyyyyyyyyyy} \\
\midrule
aaaaaaa & \multicolumn{12}{c}{\multirow{2}{*}{bbbbbbbbbbbbbb}} \\
$E=\lambda \cdot x$ & \multicolumn{12}{c}{} \\
\midrule
cccccccc & \multicolumn{4}{c}{ddddddddddddddddddd} & \multicolumn{4}{c}{eeeeeeeeeeeeeeeee} & \multicolumn{4}{c}{fffffffffffffff} \\
$P=\beta \cdot x$ & \multicolumn{4}{c}{(4)} & \multicolumn{4}{c}{(3)} & \multicolumn{4}{c}{(1)}\\
gggggggggg & \multicolumn{3}{c}{gggggggg} & \multicolumn{3}{c}{ddddddddd} & \multicolumn{3}{c}{ggggggggg} & \multicolumn{3}{c}{dsdsdsds} \\
$I=\gamma \cdot x$ & \multicolumn{3}{c}{(6)} & \multicolumn{3}{c}{(5)} & \multicolumn{3}{c}{(3)} & \multicolumn{3}{c}{(1)} \\
Calidad canal & \multicolumn{4}{c}{aaaaaaaaaaaa} & \multicolumn{4}{c}{hhhhhhhhhhhhhhhhhhhhhh} & \multicolumn{4}{c}{rrrrrrrrrrrrrrrr} \\
$\Delta = \delta \cdot x$ & \multicolumn{4}{c}{(5)} & \multicolumn{4}{c}{(3)} & \multicolumn{4}{c}{(1)} \\
\bottomrule
\end{tabular}
\end{table}
答案1
如果您有兴趣均匀分布第 1 列以外的内容,以下内容提供了更简洁的界面:
\documentclass{article}
\usepackage{booktabs,multirow,tabularx}% http://ctan.org/pkg/{booktabs,multirow,tabularx}
\newcommand{\makecell}[2][@{}c@{}]{\begin{tabular}{#1}#2\end{tabular}}
\usepackage[margin=1in]{geometry}% Just for this example
\setlength{\parindent}{0pt}% Just for this example
\begin{document}
\begin{tabularx}{\linewidth}{c X}
\toprule
xxxxxxx &
\hfill yyyyyyyyyyyyyy \hfill\null \\
\midrule
\makecell{aaaaaaa \\ $E = \lambda \cdot x$} &
\hfill bbbbbbbbbbbbbb \hfill\null \\
\midrule
\makecell{cccccccc \\ $P = \beta \cdot x$} &
\hfill \makecell{ddddddddddddddddddd \\ (4)}
\hfill \makecell{eeeeeeeeeeeeeeeee \\ (3)}
\hfill \makecell{fffffffffffffff \\ (1)} \hfill\null \\
\makecell{gggggggggg \\ $I = \gamma \cdot x$} &
\hfill \makecell{gggggggg \\ (6)}
\hfill \makecell{ddddddddd \\ (5)}
\hfill \makecell{ggggggggg \\ (3)}
\hfill \makecell{dsdsdsds \\ (1)} \hfill\null \\
\makecell{Calidad canal \\ $\Delta = \delta \cdot x$} &
\hfill \makecell{aaaaaaaaaaaa \\ (5)}
\hfill \makecell{hhhhhhhhhhhhhhhhhhhhhh \\ (3)}
\hfill \makecell{rrrrrrrrrrrrrrrr \\ (1)} \hfill\null \\
\bottomrule
\end{tabularx}
\end{document}
整个结构设置在tabularx
由两列组成。第二X
列消除了猜测要使用多少列以及表格应该有多宽的麻烦。\hfill
将内容均匀地分布在列内,而\makecell
(定义类似于makecell
包裹) 垂直堆叠元素。
\makecell
上述代码很干净,并且允许通过改变(如果需要)的定义进行定制。
答案2
要使 H2 电池垂直居中,您还需要使用包装multirow
。
\documentclass[a4paper]{article}
\usepackage{multirow}
\begin{document}
\begin{tabular}{ c c c c c }
H1 & \multicolumn{4}{c}{\multirow{2}{*}{H2}} \\
T1 \\
T1 & test & \multicolumn{2}{c}{text} & text \\
T1 & \multicolumn{2}{c}{text} & \multicolumn{2}{c}{text} \\
T1 & text & text & text & text \\
\end{tabular}
该代码将产生:
为了使包含 3 个文本的行具有均匀大小的表格,我假设需要 13 个单元格。然而,直到我在底部添加了一行空白单元格,大小仍然不正常。
\begin{tabular}{ c c c c c c c c c c c c c }
H1 & \multicolumn{12}{c}{\multirow{2}{*}{H2}} \\
T1 \\
T1 & \multicolumn{4}{c}{text} & \multicolumn{4}{c}{text} & \multicolumn{4}{c}{text} \\
T1 & \multicolumn{6}{c}{text} & \multicolumn{6}{c}{text} \\
T1 & \multicolumn{3}{c}{text} & \multicolumn{3}{c}{text} & \multicolumn{3}{c}{text} & \multicolumn{3}{c}{text} \\
& & & & & & & & & & & & \\
\end{tabular}
得出的结果为:
答案3
\multicolumn
您的代码中有一些错误的命令。
希望这是你想要的
代码:
\documentclass{article}
\usepackage{multirow,booktabs}
\begin{document}
\begin{table}[!hbt]
\centering
\caption{caption} \label{tab:table}
\begin{tabular}{c c c c c c c c c c c c c}
\toprule
xxxxxxx & \multicolumn{12}{c}{yyyyyyyyyyyyyy} \\
\midrule
aaaaaaa & \multicolumn{12}{c}{\multirow{2}{*}{bbbbbbbbbbbbbb}} \\
$E=\lambda \cdot x$ & \multicolumn{12}{c}{} \\
\midrule
cccccccc & \multicolumn{4}{c}{ddddddddddddddddddd} & \multicolumn{4}{c}{eeeeeeeeeeeeeeeee} & \multicolumn{4}{c}{fffffffffffffff} \\
$P=\beta \cdot x$ & \multicolumn{4}{c}{(4)} & \multicolumn{4}{c}{(3)} & \multicolumn{4}{c}{(1)}\\
gggggggggg & \multicolumn{2}{c}{gggggggg} & \multicolumn{2}{c}{ddddddddd} & \multicolumn{4}{c}{ggggggggg} & \multicolumn{4}{c}{dsdsdsds} \\
$I=\gamma \cdot x$ & \multicolumn{2}{c}{(6)} & \multicolumn{2}{c}{(5)} & \multicolumn{4}{c}{(3)} & \multicolumn{4}{c}{(1)} \\
Calidad canal & \multicolumn{4}{c}{aaaaaaaaaaaa} & \multicolumn{4}{c}{hhhhhhhhhhhhhhhhhhhhhh} & \multicolumn{4}{c}{rrrrrrrrrrrrrrrr} \\
$\Delta = \delta \cdot x$ & \multicolumn{4}{c}{(5)} & \multicolumn{4}{c}{(3)} & \multicolumn{4}{c}{(1)} \\
\bottomrule
\end{tabular}
\end{table}
\end{document}