# Spacing of hline after text depends on letters extending past baseline

In the following code, the hrules are different distances from the baselines. The first hrule is at the baseline of the text and the second is at the bottom of the y. How can I make them the same whether or not letters extend past the baseline?

Section x
\hrule height 0.5pt
\vspace*{1cm}
Section y
\hrule height 0.5pt


Also, why is this behavior happening? Even if I put a vspace{2pt} between each Section x/y and hrule, the spacing between the text and the lines varies. I thought vspace created a space starting at the baseline of the text.

Edit: One solution I have found to get an hrule at the baseline is to do

Section y
\\ \vspace{-\baselineskip}
\hrule height 0.5pt


but this is kind of hackish.

-

Seems that the \hrule is vertically stacked with the previous text. The y has a depth, while the x doesn't has one. I would add a \strut behind each of the two texts to force a constant (and maximal) depth for both.

Section x\strut
\hrule height 0.5pt
\vspace*{1cm}
Section y\strut
\hrule height 0.5pt

-
\strut allows for a consistent fix since it provides a maximal depth/height. A quick (and less elegant) fix would be to merely add \vphantom{y} after Section x. Or, if you want the same baseline \hrule for Section y as in Section x, try \smash{Section y}. –  Werner Aug 2 '11 at 20:43
\smash{Section y} seems to really screw things up. One thing I want to achieve is to have an hrule, text, and another hrule such that the text is perfectly centered between the horizontal lines (same distance from the top of a capital letter to the top line and from the baseline to the bottom line). How big is a strut? –  Justin J Stark Aug 2 '11 at 21:02
Taken from this Wikipedia page, a \strut has height 70% of \baselineskip and a depth of 30% of the baseline skip. Consequently, it is font-dependent and is equivalent to \rule[-.3\baselineskip]{0pt}{\baselineskip}. –  Werner Aug 3 '11 at 21:32
@Justin: In LaTeX a strut is .7\baselineskip high and .3\baselineskip deep. See Definition of \strut explained for more details, or the Wikipedia article which Werner linked (which current form got coincidently written by me a while ago based on these information) –  Martin Scharrer Aug 3 '11 at 21:38

\newcommand{\rulesection}[2][2pt]{% \rulesection[<len>]{<section title>}
\hrule height 0.5pt% top rule
\vspace*{#1}% top space
{#2}% section title
\vspace*{#1}% bottom space
\hrule height 0.5pt% bottom rule
}%


Using this, the following minimal example

\documentclass{article}

\newcommand{\rulesection}[2][2pt]{% \rulesection[<len>]{<section title>}
\hrule height 0.5pt% top rule
\vspace*{#1}% top space
{#2}% section title
\vspace*{#1}% bottom space
\hrule height 0.5pt% bottom rule
}%

\begin{document}
Section x
\vspace*{1cm}
\rulesection[0pt]{Section z}
\vspace*{1cm}
\rulesection{Section y}
\vspace*{1cm}
\rulesection[5pt]{Section p}
\end{document}​


produces

Modifying \rulesection to use {\strut #2} rather than {#2} would produce a more consistent spacing, as mentioned in Martin's answer.

-