3

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.

  • Welcome to TeX.SX! Can you show the code you added for formatting subsection titles? Please, copy and paste yours, in order to be sure that we play with the error producing code. – egreg Oct 15 '13 at 8:58
  • Please, add to your question, not as a comment. – egreg Oct 15 '13 at 9:02
  • and please make it a fully compilable example, not some sniplet where we have to guess the rest. – daleif Oct 15 '13 at 9:03
  • 1
    You should use \itshape, not \textit – egreg Oct 15 '13 at 9:04
4

In the second mandatory argument to \titleformat you should only have declarations, for what font changing commands are concerned.

So not \textit, which is a command with argument, but the corresponding declaration which is \itshape. Compare with \bfseries that's used to get boldface, not \textbf.

The difference is that \itshape tells TeX to typeset in italics from that point on (but this will be restricted to the title, because of grouping), while \textit{word} tells TeX to typeset “word” in italics.

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.