0

I have the following multicolumn table, but I would like to have these columns in different width. For example, columns "Cast name" should be wider that columns "percentage". Could someone kindly let me know how can I do it in 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}
4
  • you've given every column but the first a fixed size of 2cm. change that dimension to something larger for the columns that you want to be wider. Commented Jun 28, 2015 at 20:08
  • Then what size should I write for the \multicolumn{2}{|p{2cm}|}{Popular casts selected by users} & \multicolumn{2}{p{2cm}}{popular casts based on movies selected by users} \\ \hline & Cast name & Popularity
    – mOna
    Commented Jun 28, 2015 at 20:12
  • @mOna Well, how wide do you want them to be? You should choose the widths you want!
    – cfr
    Commented Jun 28, 2015 at 20:15
  • The | at the first \multicolumn is wrong there -- it's doubling the | there.
    – user31729
    Commented Jun 28, 2015 at 20:20

2 Answers 2

2

I suggest you drop the vertical lines completely. And increase the value for width of p columns in your \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}

enter image description here

2

I more liked this form: enter image description here

For itt I add two packages: makecell and siunitx and make p{...} column wider so, that the actors names are fit in one line:

\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}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .