Following conditions apply:
- width of each column must not exceed 25mm
- a less-wide row of a column must expand to widest row of same column (not to 25mm if the widest row is less than 25mm)
Note that using varwidth
environment inside a tikz
node creates extra space on the right of such node (which I couldn't remove, maybe you would) and makes text wrapping worse compared to when text width
is used. But text width
would expand the node from the get go to 25mm, even when text inside it is less wide than 25mm.
As a bonus, it would be nice to reduce thickness of node borders in places where they touch each other so the border of the table (as a whole) looks uniform in its thickness (and doesn't look more defined in some places compared to others).
\documentclass{standalone}
\usepackage{tikz}
\tikzset
{ every node/.style=
{ anchor=north west
}
}
\begin{document}
\begin{tikzpicture}
% 25mm ruler
\path[draw=red,line width=1pt](0,0)--(25mm,0);
% should span two columns
\path node[draw](h)
{ header/title
};
\path node[draw](r1c1)at(h.south west)
{ row 1, col 1 (abcd)
};
\path node[draw](r1c2)at(r1c1.north east)
{ row 1, col 2 (abcdefg)
};
% width should match that of row 1, col 1
% (because row 1, col 1 is wider)
\path node[draw](r2c1)at(r1c1.south west)
{ row 2, col 1
};
% width should match that of row 1, col 2
% (because row 1, col 2 is wider)
\path node[draw](r2c2)at(r2c1.north east)
{ row 2, col 2 (ab)
};
\end{tikzpicture}
\end{document}
Another take
\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{calc}
\tikzset
{ every node/.style=
{ anchor=north west
}
}
\begin{document}
\begin{tikzpicture}
% should span two columns
\path node[draw](h)
{ header/title
};
\path node
[ draw,
anchor=north east
](r1c1)at(h.south)
{ row 1, col 1 (abcd)
};
\path node[draw](r1c2)at(r1c1.north east)
{ row 1, col 2 (abcdefg)
};
% width should match that of row 1, col 1
% (because row 1, col 1 is wider)
\path node
[ draw,
anchor=north east
](r2c1)at(r1c1.south east)
{ row 2, col 1
};
% width should match that of row 1, col 2
% (because row 1, col 2 is wider)
\path node[draw](r2c2)at(r2c1.north east)
{ row 2, col 2 (ab)
};
% 25mm ruler
\path[draw=red,line width=1pt](r1c1.north east)--($(r1c1.north east)+(25mm,0)$);
\end{tikzpicture}
\end{document}
\matrix
for this, which has its own library.