# Columns don't have equal widths in table

\begin{table}[h!]
\centering
\caption{My caption}
\label{my-label}
\begin{tabular}{|l|l|l|l|l|l|l|}
\hline
\multicolumn{3}{|l|}{} & \multicolumn{2}{l|}{\begin{tabular}[c]{@{}l@{}}Filament Voltage: 6.0 V\\ Collector Voltage: 2.0 V\\ Oven Temperature: $160^{\circ}$C\end{tabular}} & \multicolumn{2}{l|}{\begin{tabular}[c]{@{}l@{}}Filament Voltage: 6.0 V\\ Collector Voltage: 2.0 V\\ Oven Temperature: $160^{\circ}$C\end{tabular}} \\ \hline
\multicolumn{3}{|l|}{\begin{tabular}[c]{@{}l@{}}Voltage at first \\ minima/maxima {[}V{]}\end{tabular}} & 0 & 2.2 & 0 & 2.2 \\ \hline
\multicolumn{3}{|l|}{\begin{tabular}[c]{@{}l@{}}Voltage at second \\ minima/maxima {[}V{]}\end{tabular}} & 4.6 & 5.2 & 4.3 & 7.2 \\ \hline
\multicolumn{3}{|l|}{\begin{tabular}[c]{@{}l@{}}Voltage at third \\ minima/maxima {[}V{]}\end{tabular}} & 9.6 & 12.4 & - & - \\ \hline
\multicolumn{3}{|l|}{\begin{tabular}[c]{@{}l@{}}Voltage difference \\ between the first and \\ the second \\ minima/maxima {[}V{]}\end{tabular}} & 4.6 & 3.0 & 4.3 & 5.0 \\ \hline
\multicolumn{3}{|l|}{\begin{tabular}[c]{@{}l@{}}Voltage difference \\ between the second and \\ the third \\ minima/maxima {[}V{]}\end{tabular}} & 5.0 & 7.2 & - & - \\ \hline
\multicolumn{3}{|l|}{\begin{tabular}[c]{@{}l@{}}Mean of Voltage \\ difference between \\ the minima/maxima {[}V{]}\end{tabular}} & 4.8 & 5.1 & 4.3 & 5.0 \\ \hline
\end{tabular}
**strong text**\end{table}


I have problem with wider columns and i could not figure out why they are not same? Can somebody help me? thank you

• Welcome to TeX.SX! Please make your code compilable (if possible), or at least complete it with \documentclass{...}, the required \usepackage's, \begin{document}, and \end{document}. That may seem tedious to you, but think of the extra work it represents for TeX.SX users willing to give you a hand. Help them help you: remove that one hurdle between you and a solution to your problem. – Martin Schröder Nov 8 '15 at 7:25
• Are you sure that you need nested tables? – Martin Schröder Nov 8 '15 at 7:26

## 1 Answer

The widths of the four columns that contain numeric data need to be calculated explicitly, because of the presence of the header cells that span two columns at a time. The code below shows how this may be accomplished.

I would further like to suggest you simplify the code in the table by letting the text in the first column wrap automatically and letting the first column's width be determined as the difference between the width of the text block and the combined widths of columns 2 through 5.

\documentclass{article}
\usepackage{tabularx,ragged2e}
% Calculate width of columns 2 to 5
\newlength\mylength
\settowidth{\mylength}{Oven Temperature: $160^{\circ}$C}
\addtolength\mylength{-2\tabcolsep}
\addtolength\mylength{-\arrayrulewidth}
\setlength\mylength{\dimexpr\mylength/2\relax}
\newcolumntype{P}[1]{>{\centering\arraybackslash}p{#1}}
% Width of column 1 is a residual
\newcolumntype{Y}{>{\RaggedRight}X}
% Handy shortcut macro
\newcommand\mc[1]{\multicolumn{2}{c|}{#1}}

\begin{document}
\begin{table}[h!]
\setlength\tabcolsep{4pt}
\caption{My caption} \label{my-label}
\begin{tabularx}{\textwidth}{|Y|*{4}{P{\mylength}|}}
\hline
& \mc{Filament Voltage: 6.0 V} & \mc{Filament Voltage: 6.0 V} \\
& \mc{Collector Voltage: 2.0 V} & \mc{Collector Voltage: 2.0 V} \\
& \mc{Oven Temperature: $160^{\circ}$C} & \mc{Oven Temperature: $160^{\circ}$C} \\
\hline
Voltage at first minimum\slash maximum [V] & 0 & 2.2 & 0 & 2.2 \\ \hline
Voltage at second minimum\slash maximum [V] & 4.6 & 5.2 & 4.3 & 7.2 \\
\hline
Voltage at third minimum\slash maximum [V] & 9.6 & 12.4 & - & - \\ \hline
Voltage difference between first and second minima\slash maxima [V] & 4.6 & 3.0 & 4.3 & 5.0 \\
\hline
Voltage difference between second and third minima\slash maxima [V] & 5.0 & 7.2 & - & - \\
\hline
Mean of Voltage difference between the minima\slash maxima [V] & 4.8 & 5.1 & 4.3 & 5.0 \\
\hline
\end{tabularx}
\end{table}
\end{document}