How to make a row in a table shorter?

LaTeX adds struts inside the table rows/cells. Each update of the font size/\baselineskip (\size@update) sets \strutbox (a box with height 0.7\baselineskip and depth 0.3\baselineskip. At the start of a tabular/array the box \@arstrutbox is set that uses the current \strutbox and scales it with factor \arraystretch.

The following example defines \setarstrut{...} that sets the table strut before the next row:

  • The argument allows font size commands, in the example: \tiny. Alternatively \arraystretch can be changed:

    \setarstrut{\renewcommand*{\arraystretch}{0.5}}%
    
  • Internally \nolign is used. Therefore \setarstrut must be at the start of the row. Otherwise it would be to late to set smaller struts anyway.
  • The old strutbox is remembered in \saved@arstrutbox.
  • Small disadvantage is the global settings of the strut box to skip the grouping levels. Thus some care is needed, if the table is nested inside another table.

Macro \saved@arstrutbox restores the saved strut box.

Example file:

\documentclass[]{article}

\makeatletter
\newsavebox\saved@arstrutbox
\newcommand*{\setarstrut}[1]{%
  \noalign{%
    \begingroup
      \global\setbox\saved@arstrutbox\copy\@arstrutbox
      #1%
      \global\setbox\@arstrutbox\hbox{%
        \vrule \@height\arraystretch\ht\strutbox
               \@depth\arraystretch \dp\strutbox
               \@width\z@
      }%
    \endgroup
  }%
}
\newcommand*{\restorearstrut}{%
  \noalign{%
    \global\setbox\@arstrutbox\copy\saved@arstrutbox
  }%
}
\makeatother

\begin{document}
  \begin{tabular}{|c|c|c|c|}
    \setarstrut{\tiny}%
    {\tiny0}&{\tiny1}&{\tiny2}&{\tiny3}\\
    \restorearstrut
    \hline
    0 & 4.94066e-323 & 22 & 9.78381e+199\\
    \hline
  \end{tabular}
\end{document}

Result


This isn't pretty, but it works:

enter image description here

\documentclass{article}
\newlength{\mylen}
\settoheight{\mylen}{\tiny 1}
\newcommand{\myheading}[1]{%
  \raisebox{\dimexpr\normalbaselineskip-\mylen}{\tiny #1}}
\begin{document}
\begin{tabular}
{|c|c|c|c|}
\myheading{0} & \myheading{1} & \myheading{2} & \myheading{3} \\[\dimexpr-\normalbaselineskip+\mylen]
\hline 0 & 4.94066e-323 & 22 & 9.78381e+199 \\
\hline 
\end{tabular}
\end{document}

This assumes you'll only use similar-height elements in the first row (using the length \mylen set to the height of {\tiny 1}).


Given the complexity of the LaTeX solution, I have no option but to post a ConTeXt solution ;-)

Like LaTeX, ConTeXt also inserts a \strut in each row of a table. However, rather than fighting the strut, we can simply ask ConTeXt not to add the strut by saying strut=no.

\startsetups table:size
  \setupTABLE[row][1][style=\tfxx, strut=no]
  \setupTABLE[align=middle]
\stopsetups

\starttext
\startTABLE[setups={table:size}]
  \NC 0 \NC 1 \NC 2 \NC 3 \NC \NR
  \NC 0 \NC 4.94066e-323 \NC 22 \NC 9.78381e+199  \NC \NR
\stopTABLE
\stoptext

enter image description here

Tags:

Height

Tables