1

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 add vertical space after the heading style?
  • How can I avoid that the subsequent text gets formatted as well?

Many thanks for your help!

\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}
  • 1
    Welcome to TeX SX! Why fon't you use \part*? You can easily customise its layout with titlesec. – Bernard Sep 3 '18 at 14:12
  • unfortuantely, I'm not very familiar with the method you suggest. How would this work? – user116514 Sep 3 '18 at 14:21
2

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}

enter image description here

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

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}

demo


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}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.