2

I am referring this question where I the following solution was suggested. The code giving me an error is the following one (copied-pasted from my LaTeX editor):

\documentclass{article}
\usepackage{titlesec}
\titleformat{\part}[hang]
  {\normalfont\LARGE\bfseries}{\thepart}{1em}{}
\titlespacing*{\part}{0pt}{3.5ex plus 1ex minus .2ex}{2.3 ex plus .2ex}
\renewcommand{\thepart}{\arabic{part}}
\let\mysection\part
\usepackage{lipsum}
\begin{document}
\mysection{A chapter} one
\mysection{another} two
\section{A section}
\end{document}

The error I receive is Package titlesec Error: Entered in horizontal mode. \mysection{another}

  • 1
    Add a blank line between the two \mysection. This being said, why don't you use the report class; to have \chapter at your disposal? – Bernard Nov 17 '19 at 22:31
  • I have noticed that adding a blank line does the job, but I am wondering where the problem lies. I don't need in particular any chapter or anything, I am trying to understand how sectioning works. – Filippo Alberto Edoardo Nov 17 '19 at 22:33
  • I wonder too. Yet, I've been using titlesec for many years, but I really don't see for this one. Maybe some guru will know – Bernard Nov 17 '19 at 22:44
  • Of course, a hack is to set \def\mysection{\par\part} instead of \let\mysection\part but this is really awful! – Filippo Alberto Edoardo Nov 17 '19 at 23:28

1 Answers1

1

The problem arises because titlesec doesn't touch definitions of \part which are usually non-standard across classes. I hadn't taken that into account in the original question. The solution is to make titlesec redefine \part by explicitly giving it a class, using the \titleclass command:

\documentclass{article}
\usepackage{titlesec}
\titleclass{\part}{straight}
\titleformat{\part}[hang]
  {\normalfont\LARGE\bfseries}{\thepart}{1em}{}
\titlespacing*{\part}{0pt}{3.5ex plus 1ex minus .2ex}{2.3 ex plus .2ex}
\renewcommand{\thepart}{\arabic{part}}
\let\mysection\part
\begin{document}
\mysection{A chapter}
one
\mysection{another}
two

\end{document}

output of code

Alan Munn
  • 218,180