Disclaimer: I am asking this question because (1) I would like to solve this problem, but (2) also because I would like to learn about what's going on under the hood with LaTeX here. Thus, I am not seeking out a package that can do this, or comments on how or why I'm doing this. I simply want an explanation of the behavior in this specific instance.
I am playing with creating a new environment with the \newenvironment command. Here's what I have:
\documentclass[12pt]{article}
\newenvironment{mytitle}{
\begin{center}
\begin{minipage}{0.5\linewidth}
\begin{center}
\rule{\linewidth}{0.4pt}
\LARGE\bfseries
}{
\rule{\linewidth}{0.4pt}
\end{center}
\end{minipage}
\end{center}
}
\begin{document}
\begin{mytitle}
Lorem Ipsum Dipsum Gypsum
\end{mytitle}
\end{document}
The result:
Question: Where is that space coming from between the end of the text and the rule? I have tried putting percent signs all over the place, changing the \parskip value, doing different kinds of line breaks, etc. What is causing this? The natural followup question is how to get rid of it, so that it looks more like this:



{followed by a new line enters a space. New lines are spaces. Use%to comment the line ending. It doesn't happen before because the line ending is preceded by a control sequence, which gobbles the space. – cfr Sep 28 '17 at 02:45\parjust after the brace that opens the "end of environment" block. (not tested) i think you're still in horizontal mode, and since the rule is the full textwidth, it will be set on a new line, at the baseline. (don't have a tex installation on my laptop, so this is just a somewhat educated guess.) – barbara beeton Sep 28 '17 at 03:04