I had the same problem as in LINK. The question is about using \endgroup somewhere. If I use the following code
\usepackage[a4paper,hmargin=1in,top=1.2in,bottom=1in]{geometry}
\usepackage{lipsum}
\usepackage{wrapfig}
\usepackage{pgfplots}
\pgfplotsset{width=10cm,compat=1.9}
\begin{document}
\begingroup
\setlength\intextsep{0pt}
\begin{wrapfigure}{r}{0pt}
\begin{tikzpicture}[scale=0.5]
\draw[step=1cm,very thin] (0,0) grid (13,8);
\end{tikzpicture}
\end{wrapfigure}
\noindent \lipsum[1]
\endgroup
\end{document}
it would look like this picture

However, if I add an empty line after \lipsum[1]
(... like above)
\noindent \lipsum[1]
\endgroup
\end{document}
it would look like this picture

Why is there a difference in the code? If I replace this empty line with \\, \newline or even \hfill \break, none changes. What does this ''empty line'' in grouping mean? Is there other way to fill this empty line to make the code work as in the second picture?
wrapfigin a group or if you do, as you show, make sure the paragraph ends before the group ends. – David Carlisle Nov 20 '22 at 21:41\setlength\intextsep{0pt}to move the figure a little bit up, only for this figure without affecting other future figures. I followed similar method in link about grouping – UnknownW Nov 20 '22 at 21:44\setlength\intextsep{0pt}in the premable, everything works as I wanted. But it would mean that all other figures would be affected by this code as well – UnknownW Nov 20 '22 at 21:52begin{wrapfigure}{r}{0pt}\vspace{-10pt}\begin{tik...– David Carlisle Nov 20 '22 at 21:56