我有以下多列表格,但我想让这些列的宽度不同。例如,“演员姓名”列应该比“百分比”列宽。有人能告诉我如何在 latex 中做到这一点吗?
\begin{table}[h]
\centering
\caption{Top 5 popular casts(1) VS popular casts(2)}
\label{table:popularCasts}
\begin{tabular}{|l|p{3.5cm}|p{0.5cm}|p{3.5cm}|p{0.5cm}|}
\toprule
Rank & \multicolumn{2}{|p{3.5cm}|}{Popular casts selected by users} & \multicolumn{2}{p{3.5cm}|}{popular casts based on movies selected by users} \\ \hline
& Cast name & Popularity
& Cast name & Popularity \\
\midrule
1 & Leonardo DiCaprio & 10 & Tom Cruise & 12\\
2 & Johnny Depp & 9 & Robert De Niro & 10\\
3 & Al Pacino & 8 & Leonardo DiCaprio & 9 \\
4 & Robert De Niro & 8 & Brad Pitt & 8\\
5 & Brad Pitt & 7& Johnny Depp & 8\\ \bottomrule
\end{tabular}
\end{table}
答案1
p
我建议你彻底删除垂直线。并增加列宽值\multicolumn
。
\documentclass[12pt]{article}
\usepackage{lmodern,array,booktabs}
\begin{document}
\begin{table}[h]
\centering
\caption{Top 5 popular casts(1) VS popular casts(2)}
\label{table:popularCasts}
\begin{tabular}{@{}l>{\raggedright}p{2cm}>{\raggedright}p{2cm}>{\raggedright}p{2cm}p{2cm}@{}}
\toprule
Rank
& \multicolumn{2}{p{4cm}}{Popular casts selected by users}
& \multicolumn{2}{p{4cm}@{}}{Popular casts based on movies selected
by users} \\ \cmidrule(lr){2-3}\cmidrule(l){4-5}
& Cast name & Popularity & Cast name & Popularity \\
\cmidrule(r){1-1}\cmidrule(lr){2-2}\cmidrule(lr){3-3}\cmidrule(lr){4-4}\cmidrule(l){5-5}
1 & Leonardo DiCaprio & 10 & Tom Cruise & 12 \\
2 & Johnny Depp & 9 & Robert De Niro & 10 \\
3 & Al Pacino & 8 & Leonardo DiCaprio & 9 \\
4 & Robert De Niro & 8 & Brad Pitt & 8 \\
5 & Brad Pitt & 7 & Johnny Depp & 8 \\ \bottomrule
\end{tabular}
\end{table}
\end{document}
答案2
我更喜欢这种形式:
对于 itt,我添加了两个包:makecell
并使列siunitx
更宽p{...}
,以便演员的名字可以放在一行中:
\documentclass[12pt]{article}
\usepackage{lmodern,caption}
\usepackage{array,booktabs,makecell}
\renewcommand\theadfont{\normalsize}
\usepackage{siunitx}
\begin{document}
\begin{table}
\centering
\caption{Top 5 popular casts(1) VS popular casts(2)}
\label{table:popularCasts}
\begin{tabular}{@{}c p{3.5cm} S
p{3.5cm} S @{}}
\toprule
& \multicolumn{2}{c}{\thead{Popular casts selected by users}}
& \multicolumn{2}{c}{\thead{Popular casts based on\\
movies selected by users}} \\
\cmidrule(lr){2-3}\cmidrule(l){4-5}
Rank & Cast name & {Popularity} & Cast name & {Popularity} \\
\midrule
1 & Leonardo DiCaprio & 10 & Tom Cruise & 12 \\
2 & Johnny Depp & 9 & Robert De Niro & 10 \\
3 & Al Pacino & 8 & Leonardo DiCaprio & 9 \\
4 & Robert De Niro & 8 & Brad Pitt & 8 \\
5 & Brad Pitt & 7 & Johnny Depp & 8 \\
\bottomrule
\end{tabular}
\end{table}
\end{document}