1

I would like to draw a hrule and have a precise control on the vertical space bewteen the line and the baseline of the text under the line.

On the following image, one can see that the space between the rule and the baseline is not the same in the three instances.

enter image description here

How can I achieve that?

Here is a MWE that demonstrate the issue.

\documentclass{article}

% see: https://tex.stackexchange.com/a/432196/8323 \newsavebox\textbox \newcommand\showbaseline[1]{% \leavevmode \sbox\textbox{#1}% \rlap{\rule{\wd\textbox}{.1pt}}% \usebox\textbox }

\begin{document}

\hrule \showbaseline{A new line}

\vspace{1cm}

\hrule \showbaseline{a new way}

\end{document}

enter image description here

Colas
  • 6,772
  • 4
  • 46
  • 96

1 Answers1

2

It's simple: TeX adds no vertical space between \hrule and the next box (which might be the first line of a paragraph, like in your example).

More precisely, after \hrule (which is a vertical command), TeX sets \prevdepth to -1000pt.

Under the assumption that the next line is not higher than usual, adding \prevdepth=0pt after \hrule would do.

\documentclass{article}

\newcommand{\test}[1]{% \makebox[0pt][l]{% \vtop{\hsize=5cm\parindent=0pt \hrule\prevdepth=0pt \makebox[0pt][l]{\vrule width 5cm height 0pt depth 0.1pt}#1 }% }% }

\begin{document}

\test{Généralités}

\medskip

\test{Électricité}

\medskip

\test{Optique}

\bigskip

%%% superimposed \test{Généralités}% \test{Électricité}% \test{Optique}

\end{document}

enter image description here

egreg
  • 1,121,712