[Tex/LaTex] Amount of space between text and a line containing a \rule

rulesspacing

If a \rule is placed below a line of text, some space is inserted between the line and the rule. Usually, the amount of space appears to precisely add the difference to the height of the current font size, regardless of whether text is actually inserted (cf. figure, right column, row 1/2) or not (left column). However, if the rule's height surpasses the font height, there is some additional space between the lines (row 3).

Of what amount is this space?

enter image description here

(The purpose of the last row is to quickly demonstrate that the identical results in spacing in the two columns in rows 1-3 are independently achieved.)

\documentclass{article}
\usepackage{calc}
\usepackage{array}
\usepackage{xparse}
\renewcommand{\arraystretch}{3.5}

\newlength{\mydepth}
\newlength{\myheight}
\newlength{\mywidth}
\newlength{\colwidth}

\newsavebox{\mybox}
\sbox{\mybox}{\Huge ipsum}
\settodepth{\mydepth}{\Huge ipsum}
\settowidth{\mywidth}{\Huge ipsum}

\setlength{\colwidth}{\mywidth+2em}


%typeset \mybox underlined with a rule of mandatory height #3,
%and place an optional text #2 either right or left of the rule,
%as indicated by a star (#1).
\DeclareDocumentCommand{\placebox}{s o m}{
    \begin{minipage}[b]{\mywidth+2em}%
    \IfBooleanTF{#1}{%
        \rule[-\mydepth]{2em}{\mydepth}%
        \usebox{\mybox}\\%
        \IfValueTF{#2}{#2}{}%
        \rule{\mywidth+1em}{#3}%
    }{%else invert left/right placement
        \usebox{\mybox}%
        \rule[-\mydepth]{2em}{\mydepth}\\%
        \rule{\mywidth+1em}{#3}%
        \IfValueTF{#2}{#2}{}%
    }%fi
    \end{minipage}%
}%

\begin{document}
\begin{tabular}{b{\colwidth}b{\colwidth}}
\placebox{1mm} & \placebox*[\Huge A]{1mm}\\[2em]
\placebox{1mm} & \placebox*[A]{1mm}\\
\placebox{2mm} & \placebox*[A]{2mm}\\
\placebox{4mm} & \placebox*[A]{4mm}\\
\end{tabular}
\end{document}

Best Answer

To understand the behaviour it is instructive to go to the TeX primitive rules. These are defined using three dimensions height, width and depth:

\vrule height1pt width 1pt depth0pt fjord\par
\hrule height1pt width 100pt depth0pt fjord

LaTeX defines the \rule using these primitives disguised as follows:

\def\rule{\@ifnextchar[\@rule{\@rule[\z@]}} width height raised
\def\@rule[#1]#2#3{%
 \leavevmode
 \hbox{%
 \setlength\@tempdima{#1}%
 \setlength\@tempdimb{#2}%
 \setlength\@tempdimc{#3}%
 \advance\@tempdimc\@tempdima
 \vrule\@width\@tempdimb\@height\@tempdimc\@depth-\@tempdima}}

If we construct an example using first the TeX primitives,

 \vrule height1pt width 1pt depth0pt fjord
 \hrule height1pt width 100pt depth0pt fjord

we get

enter image description here

We get a different behaviour with LaTeX rules as they are typeset in horizontal mode and TeX adds a normal parskip as required..

\rule{1pt}{1pt}fjord fjord fjord fjord\par
\rule{30pt}{1pt}fjord fjord fjord fjord

enter image description here

Full minimal

\documentclass{article}
\parindent0pt
\parskip0pt
\begin{document}
\vrule height0.4pt width 1pt depth0pt fjord\par
\hrule height0.4pt width 30pt depth0pt fjord

\rule{1pt}{1pt}fjord fjord fjord fjord\par
\rule{30pt}{1pt}fjord fjord fjord fjord
\end{document}

The amount of space left is normally lineskip for LaTeX plus \parskip in the examples. vary the parskip value to see how the lines get moved. Note that both start the rule at the baseline of the letters.