1
\documentclass{article}
\usepackage{blindtext}

\usepackage{titlesec}
\titleformat{\section}
  {\normalfont\scshape}{\thesection}{1em}{}
\titlespacing*{\section}
{0pt}{2ex plus 1ex minus .2ex}{1ex plus .2ex}

\newenvironment{myquote}[1]{%
  \small\par\vspace{3ex}
  \begin{minipage}{\dimexpr\linewidth -2\parindent\relax}%
    \def\myquoteauthorname{#1}%
  }{%
    \par\vspace{1ex}
    \noindent
    \hspace*{0.25\linewidth }%
      \rule{0.5\linewidth }{.4pt}
    \par\vspace{1ex}
    \centering
    \textsc{\myquoteauthorname}\par\vspace{3ex}
  \end{minipage}
  \par}

\begin{document}
\section*{Test Section}
\begin{myquote}{---Martina Navratilov}
Whoever said "It's not whether you win or lose that counts," probably lost.
\end{myquote}

\begin{myquote}{---Martina Navratilov}
Whoever said "It's not whether you win or lose that counts," probably lost.
\end{myquote}

\Blindtext[2]

\begin{myquote}{---17:31}
And do not kill your children for fear of poverty. We provide for them and for you. Indeed, their killing is ever a great sin.
\end{myquote}
\end{document}

In the above MWE the myquote environment is supposed to be indented like a normal paragraph. However, the starred version of titlesec means the first paragraph is not to be indented.

How can I have exclude myquote from that restriction?

1 Answer 1

1

You can conditionally insert \hspace*{\parindent} if \if@nobreak is true and \if@afterindent is false, that is, we're at the start of a section (of any level).

I also added a resetting of \@afterheading in the case that \if@nobreak is true, so a quote at the beginning of a section will not be immediately followed by a page break.

In the code below, if you change \lipsum[1][1-11] to \lipsum[1][1-9], the next section will be at the bottom of the page, followed by the quote and the regular two lines of text.

If I remove the “resetting” code, the quote would be at the end of the page and the text of the section on the next one.

\documentclass{article}
\usepackage{lipsum}

\usepackage{titlesec}
\titleformat{\section}
  {\normalfont\scshape}
  {\thesection}
  {1em}
  {}
\titlespacing*{\section}
  {0pt}
  {2ex plus 1ex minus .2ex}
  {1ex plus .2ex}

\makeatletter
\newenvironment{myquote}[1]{%
  \small\par\addvspace{3ex}
  \if@nobreak
    % we're at the start of a section
    % add the indent
    \if@afterindent\else\hspace*{\parindent}\fi
    % and instruct LaTeX to reset \@afterheading at the end
    \def\reset@nobreakatend{\@afterheading}%
  \else
    \def\reset@nobreakatend{}%
  \fi
  \begin{minipage}{\dimexpr\linewidth -2\parindent\relax}%
    \def\myquoteauthorname{#1}%
  }{%
    \par\vspace{1ex}
    \noindent
    \hspace*{0.25\linewidth}%
      \rule{0.5\linewidth }{.4pt}
    \par\addvspace{1ex}
    \centering
    \textsc{\myquoteauthorname}\par\vspace{3ex}
  \end{minipage}
  \par\nobreak\reset@nobreakatend}
\makeatother

\begin{document}
\section*{Test Section}
\begin{myquote}{---Martina Navrátilová}
Whoever said ``It's not whether you win or lose that counts,'' probably lost.
\end{myquote}

\lipsum[1][1-11] % with 1-9 the section will start on page 1

\begin{myquote}{---Martina Navrátilová}
Whoever said ``It's not whether you win or lose that counts,' probably lost.
\end{myquote}

\lipsum[1-2]

\section*{Test Section}
\begin{myquote}{---Martina Navrátilová}
Whoever said ``It's not whether you win or lose that counts,'' probably lost.
\end{myquote}

\lipsum[2-4]

\end{document}

enter image description here

1
  • How can I have an alternative version of your code in which a paragraph that follows myquote environment is not indented? (Curiously, I use noindentafter package, and it does not seem to work for myquote.
    – blackened
    Jul 1, 2020 at 23:48

You must log in to answer this question.

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