1

I am implementing a document design and I noticed that I am struggling to get the right distance between a rule and two test paragraphs. I have created a document class based on on article class, but changing the title page among other things. The following picture should explain what I am trying to achieve:

enter image description here

My naive approach was to do the following

\documentclass{article}
\usepackage{lipsum}

\begin{document}
\noindent \lipsum[1]
\vskip 10pt
\hrule height 1pt \relax
\vskip 10pt
\noindent \lipsum[2]

\end{document}

In the above example I was hoping to see 10pt difference between baseline of the title and the rule and 10pt difference between the rule and the authors line baseline. The actual numbers are bigger though. I think vskip is measuring from the top or bottom of a glyph appearing on the respective line, rather than from the baseline. Is it possible to set these distances with respect to baselines?

4
  • In an empty document article, just Abcdef \vskip 1ex \hrule height 0.1ex \vskip 1ex Abcdef produce the expected skips, but the adding \usepackage{lipsum}\parskip10ex in the preamble and \lipsum[1-10] at the end, force a stretch of the second vertical space without touch the chunk of code. Conclusion: Without a minimal working example (MWE) is almost always hard to understand the true problem and propose a good solution without a good crystall ball.
    – Fran
    Commented Jan 8, 2023 at 9:41
  • Thanks, @Fran. I added an MWE. I do use a fair number of packages in my document, but even after stripping everything I am seeing this problem. Maybe my way of measuring is flawed. I import to inkscape and draw a line between the two baselines. There ought to be a better approach. Commented Jan 9, 2023 at 10:08
  • It's hard to understand why you expect 52bp when you specify lengths in pt and don't specify the font size (and the corresponding baseline skip).
    – egreg
    Commented Jan 16, 2023 at 11:39
  • Sorry, @egreg, I've edited my MWE to make measuring easier for myself, but I forgot to make the text consistent. I am now trying to fix 10pt between baseline and the rule. Commented Jan 16, 2023 at 11:45

2 Answers 2

1

Between a box and an \hrule, TeX doesn't insert glue coming from calculations involving \baselineskip. But the depth of the upper box is kept into consideration.

You can remove it with \vskip-\prevdepth, no need to guess.

Similarly, no glue coming from \baselineskip calculations is inserted after the rule. If you're sure that the line below doesn't contain unusually high items, you can insert there a strut.

\documentclass{article}

\begin{document}

\noindent Abcdefg\smash{\vrule depth 9.4pt}% just a bit shorter

\vspace{\dimexpr 9.5pt-\prevdepth\relax}

\hrule height 0pt depth 1pt\relax

\vspace{\dimexpr 9.5pt-\ht\strutbox\relax}

\noindent \strut Abcdefg\smash{\vrule height 9.4pt}% just a bit shorter

\end{document}

I inserted the 1pt rule midway, so with 9.5pt of space above (with respect to the upper baseline) and 9.5pt of space below (with respect to the lower baseline). The correctness is witnessed by the vertical rules that are just a tad shorter in order to show a tiny gap.

enter image description here

1
  • Thanks, that's much nicer than measuring Hs and gs! Commented Jan 16, 2023 at 13:56
0

Fixing the distances x and y to 10pt and the depth of the rule to 1pt, I came up with the following, which appears to solve my problem:

\documentclass{article}
\usepackage{lipsum}
\newlength{\Hheight}
\settoheight{\Hheight}{H}
\newlength{\qdepth}
\settodepth{\qdepth}{g}


\begin{document}
\noindent\lipsum[1]
\vspace{\dimexpr 10pt-\qdepth\relax}
\hrule height 0pt depth 1pt\relax
\vspace{\dimexpr 10pt-\Hheight-1pt\relax}
\noindent \lipsum[2]
\end{document}

I would still appreciate a better answer or a more TeXnical explanation.

Using vspace and suggestions for computing font height and depth I found here, the first offset is simply subtracting the depth to get the baseline and then adds the desired distance to the rule. For the second offset I subtract the height of the font and the depth of my rule.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .