[Tex/LaTex] Suppress parskip BEFORE (sic!) a specific paragraph

lyx-layoutsparskip

Imagine the following document:

\documentclass{article}
\setlength{\parskip}{8pt}
\begin{document}
This is the first paragraph

This is the second paragraph

This is the third paragraph
\end{document}

I now want to modify the second (not the third!!) paragraph so that there is no spacing between the second and the third paragraph.

There are many ways to modify the third paragraph so that there is no parskip between the second and the third – but i must modify the second one.

Simplest example for a solution that does NOT fit for me:

{\setlength{\parskip}{0pt}This is the third paragraph}

Why?

The document seen here is a minimal example of LaTeX code generated by the WYSIWYM editor LyX.

In LyX, I need to create a paragraph layout style (for the second paragraph) that avoids spacing between a paragraph using that style and the following paragraph which is of any other style.

I can only modify the output of the second paragraph, because it is free to the user which style he uses for the following paragraph. All other paragraph styles are "normal" and generate a parskip, which is the normal desired behaviour. (except for the special paragraph style I want to generate)

Unfortunately, there seems to be no way to tell LyX not to generate \n\n after each style without modifying the source code.

Any ideas appreciated!

Update 1:

I found that a negative \vspace with the length of a single \parskip might do the trick, but am unsure about unforeseen consequences:

\documentclass{article}
\setlength{\parskip}{8pt}
\begin{document}
This is the first paragraph

This is the second paragraph\vspace{-\parskip}

This is the third paragraph
\end{document}

What could happen when i use the negative vspace in this context inside a large, auto-generated document?

Best Answer

While I show \noparskip at the end of the 2nd paragraph, it can appear anywhere in the paragraph (INCLUDING the very beginning) and achieve the same effect.

EDIT: My concern with using a simple negative \vspace revolves around pagination that might be artificially brought on by the larger \parskip, prior to the invocation of the negative \vspace. Whether that is an issue in Lyx, I have no experience to know. I suppose though, that issuing the negative \vspace prior to the closing \par may be a safe option, but I'll let others comment.

\documentclass{article}
\setlength{\parskip}{8pt}
\let\svpar\par
\edef\svparskip{\the\parskip}
\def\revertpar{\svpar\setlength\parskip{\svparskip}\let\par\svpar}
\def\noparskip{\leavevmode\setlength\parskip{0pt}%
  \def\par{\svpar\let\par\revertpar}}
\begin{document}
This is the first paragraph

This is the second paragraph\noparskip  

This is the third paragraph

This is the fourth paragraph
\end{document}

enter image description here

Related Question