Error when trying to indent a run-in subsection

For some reason I cannot indent a \subsubsection{} that is formatted by the titlesec package using the [runin] option. The run-in option is for making the paragraph follow immediately after the \subsubsection{} heading, which in my case I leave it blank and use only the numbers.

The file:

\documentclass{article}
\usepackage{titlesec}

\setcounter{secnumdepth}{3}
\titleformat{\subsection}[runin]{}{\thesubsection.}{3pt}{}
\titleformat{\subsubsection}[runin]{}{\thesubsubsection.}{3pt}{}

\begin{document}

\section{This is a section}

\subsection{} This is a paragraph:

\begin{quote}
\subsubsection{} This is a sub-paragraph I want to indent.
\end{quote}

\subsubsection{} This is a sub-paragraph I want to indent.
}

\end{document}


This generates the following output:

Notice that the first method works, but it makes an error:

Something's wrong--perhaps a missing \item.

The second method does nothing at all.

Now if I remove the [runin] option both methods work just as expected. It seems that the [runin] option interferes with indentation. However, despite the error the first method seems to produce the desired document. Any idea how to eliminate the error?

• Do you want all subsubsection titles to be run-in and indented? – egreg Nov 9 '17 at 0:28
• The quote environment is implemented as a list, so you can't embed a section inside it. That's why you get the error. Do you want all subsubsections to be indented? If so, then use titlesec to do that. – Alan Munn Nov 9 '17 at 0:28
• Yes, I want all \subsubsections to be indented, how should I do that? – Yan King Yin Nov 9 '17 at 0:39

You're better using \titlespacing. The last two parameters are taken from the values in article.cls.

\documentclass{article}
\usepackage{titlesec}
\usepackage{lipsum}

\setcounter{secnumdepth}{3}
\titleformat{\subsection}[runin]{}{\thesubsection.}{3pt}{}
\titleformat{\subsubsection}[runin]{}{\thesubsubsection.}{3pt}{}
\titlespacing{\subsubsection}{\parindent}{3.25ex plus 1ex minus .2ex}{1.5ex plus .2ex}

\begin{document}

\section{This is a section}
\lipsum[2]

\subsection{} This is a paragraph:
\lipsum[2]

\subsubsection{} This is a sub-paragraph I want to indent.
\lipsum[2-3]

\end{document}


If you want to indent the whole block, then adjustwidth can do it, but for implementation reasons you need to issue \mbox{}\vspace{-\baselineskip}. The problem is that adjustwidth is implemented as a list and this conflicts with run-in titles.

\documentclass{article}
\usepackage{titlesec}
\usepackage{changepage}
\usepackage{lipsum}

\setcounter{secnumdepth}{3}
\titleformat{\subsection}[runin]{}{\thesubsection.}{3pt}{}
\titleformat{\subsubsection}[runin]{}{\thesubsubsection.}{3pt}{}

\begin{document}

\section{This is a section}
\lipsum[2]

\subsection{} This is a paragraph:
\lipsum[2]

\subsubsection{} This is a sub-paragraph I want to indent.
\lipsum[2-3]

\end{document}


A perhaps better implementation with a proper environment:

\documentclass{article}
\usepackage{titlesec}
\usepackage{changepage}
\usepackage{xpatch}
\usepackage{lipsum}

\setcounter{secnumdepth}{3}

\xpatchcmd{\subsubaw}
{\topsep}
{\labelwidth=0pt \labelsep=0pt \topsep}
{}{}
\xpatchcmd{\subsubaw}
{\item[]}
{\refstepcounter{subsubsection}\item[\thesubsubsection.\hspace{3pt} ]}
{}{}
\newenvironment{subsub}
\subsubaw{\parindent}{0pt}}

\titleformat{\subsection}[runin]{}{\thesubsection.}{3pt}{}

\begin{document}

\section{This is a section}
\lipsum[2]

\subsection{} This is a paragraph:
\lipsum[2]

\begin{subsub}
This is a sub-paragraph I want to indent.
\lipsum[2-3]
\end{subsub}

\end{document}

• Sorry, by "indentation" I mean the whole block should be indented, not just the heading... can that be done? – Yan King Yin Nov 9 '17 at 0:41
• @YanKingYin Added the workaround – egreg Nov 9 '17 at 1:05
• Is there no way to automate this? – Alan Munn Nov 9 '17 at 1:16
• @AlanMunn Yes, see last version – egreg Nov 9 '17 at 1:19
• Great! Then you should also add that as an answer here: tex.stackexchange.com/questions/109328/… – Alan Munn Nov 9 '17 at 1:21