# How to change column width on each row?

I am trying to create a table layout such that my first row has different column spacing than the rest of the table. It's a header (well, part of a pair of headers) for a table of names.

The layout I'm trying to achieve is:

+--------------------------------------+
| Title             | Report Number    |  % These columns 50% width
+--------------------------------------+
| Name     | Responsibility            |
+--------------------------------------+
| Data     | Data                      |
| Data     | Data                      |
+--------------------------------------+


This would span the width of the page.

My initial thought was to lay the table out as 4 columns, and span two columns in the first row to get the 50/50 layout, then span 1 and 3 columns for the data portion. I thought I had read that multicolumn's in tabularx wasn't recommended, but I'm not able to find that at this moment.

Another approach I am working through is stacking tables on top of each other (table 1 has the first header row, which is unique, table 2 has the data), but the 2nd table seems to be indented due to being immediately after a section header.

My current code is as follows:

\section*{TEAM MEMBERS}

\newcolumntype{Y}{>{\centering\arraybackslash}X}
\cellcolor[HTML]{EFEFEF}\textbf{#1}
}

\begin{tabularx}{\textwidth}{Y|Y}
\tableheader{\@title} & Report Number: \@reportproject \\
\end{tabularx}

\begin{tabularx}{\textwidth}{X|X}
Name & Responsibility \\
Class that has many accessor methods and accesses a lot of external data & ATFD is more than a few\\
Class that is large and complex & WMC is high\\
Class that has a lot of methods that only operate on a proper subset of the instance variable set & TCC is low\\
\end{tabularx}

• Usually, every new paragraph is indented, except if it comes right after a new section. To not indent, use \noindent at the beginning of the corresponding paragraph. In your case, I would also delete the empty line between the two tabularx (or write a % at the beginning of the line), since it is not necessary and makes TeX believe that the second table lives in a different paragraph. – jarauh Nov 24 '15 at 17:45
• You should use \makeatletter ... \makeatother around any code which uses the @ symbol. And we could really use a full MWE in order to figure out which packages some these definitions came from. – John Kormylo Nov 24 '15 at 18:55
• Yeah, I've been able to solve the indent issue, but I'm left with a seam between tables.. so I'm not totally sold on it being a suitable solution – Tim Nov 24 '15 at 19:26
• @Tim, your MWE doesn't reflect sketch which you show in your question! In it are long text in the first (narrower) column and short one int second (wider) column. Can you clarified this? – Zarko Nov 24 '15 at 20:31

You don't need tabularx, that's all. ;-)

\documentclass{article}
\usepackage{array}

\newcommand{\calcfactor}[1]{%
\dimexpr#1\textwidth-2\tabcolsep-1.5\arrayrulewidth\relax
}
\newcolumntype{P}[1]{p{\calcfactor{#1}}}

\begin{document}

\noindent
\begin{tabular}{|P{.25}|P{.75}|}
\hline
\multicolumn{2}{|c|}{%
\makebox[\calcfactor{.5}][l]{Title}%
\hspace{\tabcolsep}\vline\hspace{\tabcolsep}%
\makebox[\calcfactor{.5}][l]{Report number}%
}\\
\hline
Name & Responsibility \\
\hline
Data & Data \\
Data & Data \\
\hline
\end{tabular}

\end{document}


• What an amazing approach!! This just became one of my favorite answers on this stack exchange. – Chthonic Project Sep 28 '18 at 19:56
• @ChthonicProject Not the simplest syntax, but, hey! It works! ;-) – egreg Sep 28 '18 at 20:21

If your first row has say 3 columns, you can convert it into 2 columns by merging any 2 columns. In this way you can set you table header as well as data fields. Here is an example, try this:

\begin{tabular}{|c|c|l|l|}
\hline
1,1 & 1,2 & 1,3 & 1,4 \bigstrut \\ \hline
2,1 &
\multirow{2}[4]{1.5cm}{Four bigstruts} &
\multirow{3}[6]{*}{Six bigstruts} &
\multirow{3}[6]{*}[1ex]{Six bigstruts and fixup}
\bigstrut \\ \cline{1-1}
3,1 & & & \bigstrut \\ \cline{1-2}
4,1 & 4,2 & & \bigstrut \\ \hline
5,1 &
8
\multirow{2}[2]{*}{Two bigstruts}
& 5,3
& 5,4 \bigstrut[t] \\
6,1 & & 6,3 & 6,4 \bigstrut[b] \\ \hline
7,1 &
\multicolumn{2}{l|}{\multirow{2}[4]{*}{Four bigstruts}}
& 7,4 \bigstrut \\ \cline{1-1}\cline{4-4}
8,1 &
\multicolumn{2}{l|}{}
& 8,4 \bigstrut \\ \hline
9,1 & 9,2 & 9,3 & 9,4 \bigstrut \\ \hline
\end{tabular}