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

Learn LaTeX easily with newest books:

The LaTeX Beginner's Guide: 2nd edition and perfect for students writing a thesis

The LaTeX Cookbook: 2nd edition full of practical examples for mathematics, physics, chemistry, and more

LaTeX Graphics with TikZ: the first book about TikZ for perfect drawings in your LaTeX thesis

User avatar
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