Custom heading text style using \newcommand

I'm trying to create a custom heading style that is centered, bold, large and has some 0.2cm vertical space before and after. I'd like to retain the normal section headings. Below is my attempt using \newcommand.

My questions:

• How can I avoid that the subsequent text gets formatted as well?

\documentclass{article}

\newcommand\progtitel{\vspace{0.2cm}\centering\normalfont\Large\bfseries}

\begin{document}

\section{My section}
Normal text normal text normal text normal text normal text

\progtitel{Custom Title}

Normal text normal text normal text normal text normal text

\end{document}

• Welcome to TeX SX! Why fon't you use \part*? You can easily customise its layout with titlesec. Sep 3 '18 at 14:12
• unfortuantely, I'm not very familiar with the method you suggest. How would this work? Sep 3 '18 at 14:21

There is a starting point. You were missing a \vspace and a grouping of the command, which now only takes one argument.

\documentclass{article}

\newcommand\progtitel[1]{{\vspace{0.2cm}\begin{center}\Large\bfseries #1 \end{center}\vspace{0.2cm}}}

\begin{document}

\section{My section}

Normal text normal text normal text normal text normal text

\progtitel{Custom Title}

Normal text normal text normal text normal text normal text

\end{document}


• exactly what I needed - many thanks! Sep 3 '18 at 14:20

The tricky bit was making it independent of \parskip and having it behave the same with or without blank lines around it.

\documentclass{article}

\makeatletter
\newcommand{\progtitel}[1]% #1 = title
{\vspace{\dimexpr 0.2cm-\parskip}\hrule height0pt
\noindent\parbox{\columnwidth}{\centering\normalfont\Large\bfseries #1}%
\vspace{\dimexpr 0.2cm-\parskip}\hrule height0pt
\@afterheading}% no indentation for first paragraph
\makeatletter

%\parskip=\baselineskip

\begin{document}

\section{My section}
Normal text normal text normal text normal text normal text

\progtitel{Custom Title}

Normal text normal text normal text normal text normal text

\end{document}


This solution using a trivlist instead of \hrule, but the end result is more complicated, not less.

\documentclass{article}

\makeatletter
\newcommand{\progtitel}[1]% #1 = title
{\bgroup
\topsep=\dimexpr 0.2cm-\parskip\relax
\partopsep=0pt
\trivlist
\item\parbox{\columnwidth}{\centering\normalfont\Large\bfseries #1}%
\endtrivlist
\egroup\@afterheading}% no indentation for first paragraph
\makeatletter

%\parskip=\baselineskip

\begin{document}

\section{My section}
Normal text normal text normal text normal text normal text

\progtitel{Custom Title}

Normal text normal text normal text normal text normal text

\end{document}