0

For my text document with the book class I start each new chapter with an abstract. The format of this abstract section is designed such that the abstract header is indented with respect to the abstract text, like:

   Abstract
Insert text here

The abstract is designed as an environment with the NewDocumentEnvironment command.

However when the titlesec package is included in the document, the indent of the abstract header is removed.

How can I keep the indent in the abstract header, or how can I tell the titlesec package to not touch the section header formatting?

The titlesec package is included because I want to customize the chapter title (and only the chapter titles).

A MWE (toggle the titlesec package to check the indentation):

\documentclass{book}
\usepackage{titlesec}
\usepackage{xparse} 
\usepackage{changepage}
\usepackage{blindtext}
\usepackage[T1]{fontenc} % Output font encoding for international characters


\NewDocumentEnvironment{ChapterAbstract}{}
    {
        % Change the margins of the abstract relative to the regular text
        \begin{adjustwidth}{15pt}{15pt} 
        \nointerlineskip\leavevmode % Necessary addition due to the macro expansion of adjustwidth. Solves the 'missing item' error
        \section*{\indent\scshape\large abstract} % Smallcaps abstract title in \large fontsize with an indentation
        \itshape
    }
    {
        \end{adjustwidth}
    }

    \begin{document}


    \chapter{Chapter title test here}
    \begin{ChapterAbstract}
    \blindtext
    \end{ChapterAbstract}

    \section{Test section}
    \blindtext
    \end{document}
  • Welcome to TeX SX! I have no problem with this code. Are you sure the indent disappears with just this code? – Bernard Jan 8 at 18:23
  • If I toggle the titlesec package on or off, the indentation of the abstract section header changes on my pc. If it doesn't for you, I am not sure why, – tobyvd Jan 8 at 19:36
  • Rien de tel chez moi. – Bernard Jan 8 at 20:23
0

titlesec sets \parindent to 0pt inside the section heading, so \indent introduces an indentation of 0pt in your MWE. You can get the same effect by inserting a space of the same length manually using \hspace:

\documentclass{book}
\usepackage{titlesec}
\usepackage{xparse} 
\usepackage{changepage}
\usepackage{blindtext}
\usepackage[T1]{fontenc} % Output font encoding for international characters

\NewDocumentEnvironment{ChapterAbstract}{}
{
    % Change the margins of the abstract relative to the regular text
    \begin{adjustwidth}{15pt}{15pt} 
    \nointerlineskip\leavevmode % Necessary addition due to the macro expansion of adjustwidth. Solves the 'missing item' error
    \section*{\hspace{15pt}\scshape\large abstract} % Smallcaps abstract title in \large fontsize with an indentation
    \itshape
}
{
    \end{adjustwidth}
}

\begin{document}


\chapter{Chapter title test here}
\begin{ChapterAbstract}
\blindtext
\end{ChapterAbstract}

\section{Test section}
\blindtext
\end{document}

output

  • Thanks, this helped! So silly, I added \hspace{} in front of \section*{}, but that didn't work. Somehow I didn't think to try putting it inside the \section*{} command. Thanks for the quick answer. – tobyvd Jan 8 at 19:41
  • @tobyvd: You're welcome. – Circumscribe Jan 8 at 19:55

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.
https://tex.stackexchange.com/questions/469221/titlesec-package-removes-indents-from-section-headers
tex.stackexchange.com
crawl=CC-MAIN-2019-30
145231
application/http; msgtype=response
sha1:DZLUGDF6H756ONMQ7VDPHCRFYKL7YC52
<urn:uuid:6b6e033a-a144-4c42-9b89-a950712796c6>
2019-07-20T18:07:02Z
151.101.65.69
text/html
sha1:4SSGYDRHMJMBLB5QWDUOXYQBMMQUQVKX
<urn:uuid:6006780f-6ef5-45f6-8152-5c6ddc1ad0e7>
https://tex.stackexchange.com/questions/469221/titlesec-package-removes-indents-from-section-headers
response
<urn:uuid:01059c59-db17-4eb4-8790-45b1a9881e60>
isPartOf: CC-MAIN-2019-30
publisher: Common Crawl
description: Wide crawl of the web for July 2019
operator: Common Crawl Admin (info@commoncrawl.org)
hostname: ip-10-71-190-198.ec2.internal
software: Apache Nutch 1.15 (modified, https://github.com/commoncrawl/nutch/)
robots: checked via crawler-commons 1.1-SNAPSHOT (https://github.com/crawler-commons/crawler-commons)
format: WARC File Format 1.1
conformsTo: http://iipc.github.io/warc-specifications/specifications/warc-format/warc-1.1/