2

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}

{\addtolength{\leftskip}{5mm}
\subsubsection{} This is a sub-paragraph I want to indent.
}

\end{document}

This generates the following output:

enter image description here

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?

3
  • 1
    Do you want all subsubsection titles to be run-in and indented?
    – egreg
    Commented Nov 9, 2017 at 0:28
  • 1
    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
    Commented Nov 9, 2017 at 0:28
  • Yes, I want all \subsubsections to be indented, how should I do that? Commented Nov 9, 2017 at 0:39

1 Answer 1

3

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}

enter image description here

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]

\begin{adjustwidth}{\parindent}{0pt}\mbox{}\vspace{-\baselineskip}
\subsubsection{} This is a sub-paragraph I want to indent.
\lipsum[2-3]
\end{adjustwidth}

\end{document}

enter image description here

A perhaps better implementation with a proper environment:

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

\setcounter{secnumdepth}{3}

\let\subsubaw\adjustwidth
\xpatchcmd{\subsubaw}
  {\topsep}
  {\labelwidth=0pt \labelsep=0pt \topsep}
  {}{}
\xpatchcmd{\subsubaw}
  {\item[]}
  {\refstepcounter{subsubsection}\item[\thesubsubsection.\hspace{3pt} ]}
  {}{}
\newenvironment{subsub}
 {\par\addvspace{3.25ex plus 1ex minus .2ex}%
  \subsubaw{\parindent}{0pt}}
 {\endadjustwidth}

\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}
5
  • Sorry, by "indentation" I mean the whole block should be indented, not just the heading... can that be done? Commented Nov 9, 2017 at 0:41
  • 1
    @YanKingYin Added the workaround
    – egreg
    Commented Nov 9, 2017 at 1:05
  • Is there no way to automate this?
    – Alan Munn
    Commented Nov 9, 2017 at 1:16
  • 1
    @AlanMunn Yes, see last version
    – egreg
    Commented Nov 9, 2017 at 1:19
  • Great! Then you should also add that as an answer here: tex.stackexchange.com/questions/109328/…
    – Alan Munn
    Commented Nov 9, 2017 at 1:21

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .