With reference to the question: Change size of section, subsection, subsubsection, paragraph and subparagraph title
I tried this. While it works, it produces the following error when compiling:
./TexFile.tex:101: Package titlesec Error:
Entered in hori
zontal mode.
l.101 \subsection{My Subsection}
And hitting return for more info reveals:
? h
The <format> argument cannot contain horizontal material such as text, \noindent, \makebox, etc.
?
This happens even when I copy and paste the code from Gonzalo's answer, using the following code to instigate subsections:
\subsection{MySubsection}
Interestingly, the error is not occurring on sections, only subsections and subsubsections.
Edit:
Here's my code:
\usepackage{titlesec}
\titleformat{\section}{\sffamily\Large\bfseries}{\thesection}{1em}{}
\titlespacing{\section}{0pt}{2ex}{1ex}
\titleformat{\subsection}{\sffamily\textit}{\thesubsection}{1em}{}
\titlespacing{\subsection}{0pt}{1ex}{0ex}
\titleformat{\subsubsection}{\sffamily\textit}{\thesubsubsection}{1em}{}
\titlespacing{\subsubsection}{0pt}{0.5ex}{0ex}
\titleformat{\paragraph}[runin]{\normalfont\normalsize\bfseries}{\theparagraph}{1em}{}
\titleformat{\subparagraph}[runin]{\normalfont\normalsize\bfseries}{\thesubparagraph}{1em}{}
Further to daleif's request, and for anyone else with this issue, here's a minimal working example of the error:
\documentclass{article}
\usepackage{titlesec}
\titleformat{\section}{\sffamily\Large\bfseries}{\thesection}{1em}{}
\titlespacing{\section}{0pt}{2ex}{1ex}
\titleformat{\subsection}{\sffamily\textit}{\thesubsection}{1em}{}
\titlespacing{\subsection}{0pt}{1ex}{0ex}
\titleformat{\subsubsection}{\sffamily\textit}{\thesubsubsection}{1em}{}
\titlespacing{\subsubsection}{0pt}{0.5ex}{0ex}
\titleformat{\paragraph}[runin]{\normalfont\normalsize\bfseries}{\theparagraph}{1em}{}
\titleformat{\subparagraph}[runin]{\normalfont\normalsize\bfseries}{\thesubparagraph}{1em}{}
\begin{document}
\section{Section1}
\subsection{Subsection}
Minimal working example
\end{document}
This reproduces the error in compiling and, when egreg's answer is applied, it no longer occurs.
\itshape, not\textit– egreg Oct 15 '13 at 09:04