Graphics, Figures & Tablesthreeparttable | Problem with Column Width

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
ocs
Posts: 3
Joined: Sun Jul 17, 2011 4:56 pm

threeparttable | Problem with Column Width

Post by ocs »

I am using threeparttable package to create a table with footnote. However, I couldn't get the last two columns to have equal width.

Code: Select all

\usepackage{threeparttable}

\begin{table}
\centering
\begin{threeparttable}
\caption{Caption}
\begin{tabular}{|c|c|c|c|c|c|}
\hline
\multicolumn{1}{|c|}{\multirow{2}{*}{\textbf{AAAAA}}}&
\multicolumn{1}{c|}{\multirow{2}{*}{\textbf{BBBBB}}}&
\multicolumn{2}{c|}{\textbf{CCCCC}} &
\multicolumn{2}{c|}{\textbf{DDDDDDDD}}\bigstrut\\
\cline{3-6}
& & $a > b$ & $b > a$ & $a > b$ & $b > a$\\
\hline
P & S & 10\tnote{1} & 10 & 10 & 10 \\
Q & T & 10 & 10 & 10 & 10 \\
\hline
\end{tabular}
\begin{tablenotes}
\item[1] Note.
\end{tablenotes}
\end{threeparttable}
\end{table}
Please help.
Thank you in advance.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

toastermm
Posts: 8
Joined: Wed Feb 02, 2011 5:37 pm

threeparttable | Problem with Column Width

Post by toastermm »

At first, I thought this was an easy fix, as in just specifying your column widths, but latex assumes left alignment when you do that. In order to get around this, you need to make your own column label command, I called it 'x' in the below example.

Code: Select all

\documentclass[a4paper,10pt]{article}

\usepackage{threeparttable, multirow, bigstrut, array}

\newcolumntype{x}[1]{%
>{\centering\hspace{0pt}}p{#1}}%

\begin{document}

\begin{table}
\centering
\begin{threeparttable}
\caption{Caption}
\begin{tabular}{|x{1cm}|x{1cm}|x{1cm}|x{1cm}|x{1cm}|c|}
\hline
\multicolumn{1}{|c|}{\multirow{2}{*}{\textbf{AAAAA}}}&
\multicolumn{1}{c|}{\multirow{2}{*}{\textbf{BBBBB}}}&
\multicolumn{2}{c|}{\textbf{CCCCC}} &
\multicolumn{2}{c|}{\textbf{DDDDDDDD}}\bigstrut\\
\cline{3-6}
& & $a > b$ & $b > a$ & $a > b$ & $b > a$\\
\hline
P & S & 10\tnote{1} & 10 & 10 & 10 \\
Q & T & 10 & 10 & 10 & 10 \\
\hline
\end{tabular}
\begin{tablenotes}
\item[1] Note.
\end{tablenotes}
\end{threeparttable}
\end{table}

\end{document}

Try that. It worked on mine.
Post Reply