I would like to know how I can minimize the height of a row with empty table cells to zero, or to put the question in another form: How to make the minimum height of a row zero, so it will exactly take on the height of anything that I pass in the table cells of that row, regardless of how tiny it is.
I know about the \\[...]
syntax, but what is the right length to enter (actually: subtract) there (as it is depending on the font height obviously)? Can anybody tell me how the default height is constructed in tabular like environments, so I can use this formula to fill in the corresponding negative length via \\[...]
?
Or is there a trick to remove the "default" strut in a cell (this is how I understand it is being done but I may be wrong as all of this how the array package constructs the \halign
is way beyond my current understanding), so it collapses to whatever I put in there (e.g. a rule with a height of 2 pt or so)?
Because the understandable wish for an example was articulated I will try to explain the what and why a bit better, and give some example code that demonstrates what I want to achieve, and how this is done incorporating the solution given by Donald Arseneau.
The initial need is to typeset a table with chords and their allowed tensions, weak and strong harmonies and avoid notes. It doesn't matter if you don't get what I am talking about, just think of the periodic table of elements, this has a similar need for color and very selective borders around cells, only that in my case I would also want to vary the border thickness and border color (yes, I know about booktabs.sty - you simply have to believe me that the typographical remarks there don't apply at all to my situation.)
What I present is not my final product but still a synthetic example with an evolution of what I tried and what my current state is (with remarks given here referring to the 4 different approaches/evolutionary steps I show).
First the code
\documentclass[10pt]{article}
\usepackage{array}
\usepackage[table]{xcolor}
\usepackage{ehhline} % Important: this needs version >= 1.1
\usepackage{lipsum}
%%% just some shortcuts to make live easier
\definecolor{lred}{rgb}{1,0.85,0.85}
\definecolor{lgreen}{rgb}{0.85,1,0.85}
\definecolor{lblue}{rgb}{0.85,0.85,1}
\definecolor{lgray}{rgb}{0.85,0.85,0.85}
%%% define the thickness of inner lines
\def\irw{3pt}
\def\rrh{-\dimexpr\arraystretch\normalbaselineskip-\irw\relax} % used in example 4
% To make it possible to read the \\hhlines below
% w/o wanting to shoot yourself in the head:
\newcommand\arc[1]{\arrayrulecolor{#1}}
% Shortcut used for solution with !{...} of \ehhline: A coloured rule segment
\newcommand\crs[2]{\leaders\hbox{\textcolor{#1}{\rule{0.1pt}{#2}}}\hfil}
\begin{document}
\begin{center}\Large
\begin{tabular}{| >{\columncolor{lred}}c>{\columncolor{lgreen}}c
>{\columncolor{lblue}}c >{\columncolor{lgray}}c |}
\hline
{\normalsize I} & & & \\
\hhline{|~>{\arc{red}}--~>{\arc{black}}|}
& \multicolumn{1}{!{\color{red}\vline} >{\cellcolor{lgreen}}c}{+}
& \multicolumn{1}{>{\cellcolor{lblue}}c !{\color{red}\vline}}{+}
& \\
\hhline{|~>{\arc{red}}--~>{\arc{black}}|}
{\normalsize II} & & & \\
\hhline{>{\arc{black}}|>{\arc{lred}}->{\arc{red}}-->{\arc{lgray}}->{\arc{black}}|}
& \multicolumn{1}{!{\color{red}\vrule width \irw} >{\cellcolor{lgreen}}c}{+}
& \multicolumn{1}{>{\cellcolor{lblue}}c !{\color{red}\vrule width \irw}}{+}
& \\
\hhline{>{\arc{black}}|>{\arc{lred}}->{\arc{red}}-->{\arc{lgray}}->{\arc{black}}|}
{\normalsize III} & & & \\
\hhline{|!{\crs{lred}{\irw}}!{\crs{red}{\irw}}!{\crs{red}{\irw}}!{\crs{lgray}{\irw}}|}
& \multicolumn{1}{!{\color{red}\vrule width \irw}>{\cellcolor{lgreen}}c}{+}
& \multicolumn{1}{>{\cellcolor{lblue}}c!{\color{red}\vrule width \irw}}{+}
& \\
\hhline{|!{\crs{lred}{\irw}}!{\crs{red}{\irw}}!{\crs{red}{\irw}}!{\crs{lgray}{\irw}}|}
{\normalsize IV} & & & \\
& \multicolumn{2}{>{\cellcolor{red}}c}{} & \\[\rrh]
& \multicolumn{1}{!{\color{red}\vrule width \irw}>{\cellcolor{lgreen}}c}{+}
& \multicolumn{1}{>{\cellcolor{lblue}}c!{\color{red}\vrule width \irw}}{+}
& \\
& \multicolumn{2}{>{\cellcolor{red}}c}{} & \\[\rrh]
& & & \\
\hline
\end{tabular}
\end{center}
\end{document}
and this is the result:
Remarks:
I) This is the most naive way with \hhline
. Features the dreaded white space where no rule segment should be. Also no increased thickness.
II) Using correctly colored line segments everywhere in the \hhline
and placing fat \vstruts
via \multicolumn{1}...
helps to get there partially, but I see no way to make the horizontal part thicker with this approach. And already I have the impression that it gets cluttered and an excessive effort to handle the white space correctly.
III) Using ehhline.sty
and \leaders
in the \hhline
. Works (I think the little missing part at the right is an artefact of the pdf viewer's zooming). It simply feels like an incredibly excessive effort to reach the result, and would be completely unreadable without the defined shortcuts.
Side question: Does anybody know a more elegant way than to stick tiny rules via \leaders
together here (see the definition of \crs
in my code)? How could I just put in one correctly sized rule in there? Is there any way to get to the computed column width?
IV) Trying to minimize the effort, I thought about skipping \hline
and related altogether and instead construct the vertical rules as regular cells. This is where the question arose. With the right amount of skipping back and adding my thickness it works.
So I have two possible ways now, but unfortunately they don't yet solve all cases. I need in one table bordered cells with differing widths. Obviously both III) and IV) assume one thickness for horizontal borders per row. So I am trying to stop using the cell itself as a rule, but instead use the cells only for background coloring and again sticking in rules for the borders (which would need to be aligned at the bottom for top borders and aligned to the top for bottom borders). But here I am back at my side question above: I would need a way to insert colored rules of the computed column width and the desired thickness into cells that hold the border. This is currently unsolved for me.
\documentclass{...}
and ending with\end{document}
.\halign
primitive. The various border width plays a minor role because we can set outer widths of all bordered elements the same (as the picture shows).