Loosing top/bottom theorem spacing when using adjustwidth

I can propose not using adjustwidth, but a small modification of https://tex.stackexchange.com/a/67251/4427

The trick with \normalparindent is necessary in order to avoid timing problem (in a \list the \parindent parameter is set to zero).

\documentclass{book}

\usepackage{lipsum}% just to generate text for the example
\usepackage{amsmath, mathtools,amssymb,amscd,amsthm,amstext}
\usepackage{etoolbox}

\makeatletter
\patchcmd{\@thm}
  {\trivlist}
  {\list{}{\leftmargin=\thm@leftmargin\rightmargin=\thm@rightmargin}}
  {}{}
\patchcmd{\@endtheorem}
  {\endtrivlist}
  {\endlist}
  {}{}
\newlength{\thm@leftmargin}
\newlength{\thm@rightmargin}

\newcommand{\xnewtheorem}[3]{%
  \newenvironment{#3}
    {\thm@leftmargin=#1\relax\thm@rightmargin=#2\relax\begin{#3INNER}}
    {\end{#3INNER}}%
  \newtheorem{#3INNER}%
}
\newlength{\normalparindent}
\setlength{\normalparindent}{1sp}
\AtBeginDocument{\setlength{\normalparindent}{\parindent}}
\makeatother

% Redefine theorem style
\newtheoremstyle{mytheoremstyle} % name
    {\topsep}                    % Space above
    {\topsep}                    % Space below
    {\itshape}                   % Body font
    {\normalparindent}           % Indent amount
    {\bfseries}                  % Theorem head font
    {.}                          % Punctuation after theorem head
    {0.5em}                      % Space after theorem head
    {}                           % Theorem head spec (can be left empty, meaning ‘normal’)
\theoremstyle{mytheoremstyle}
\xnewtheorem{.6cm}{.6cm}{theorem}{Theorem}[chapter] 

\begin{document}
\lipsum[1-1]
\begin{theorem}
   This theorem looks correct, but I haven't applied any indentation. 
   It follows the indentation of the document.
\end{theorem}
\lipsum[1-1]
\begin{theorem}
   This theorem has had indentation applied and the result is different
   spacing above and below it.
\end{theorem}
\lipsum[1-1]
\end{document}

enter image description here


This is a generic problem with theorem environment (the one as redefined by amsthm) being used as the first thing following an \item. (there is an hidden \item from the adjustwidth environment). This goes a bit deep into LaTeX's management of lists.

Rather than patching theorem, I propose here a hack on adjustwidth, which may be enough for your document, but may have aftereffects I have not tried to discover. Done with etoolbox's \apptocmd, for commodity.

\documentclass{book}

\usepackage{lipsum}% just to generate text for the example
\usepackage{amsmath, mathtools,amssymb,amscd,amsthm,amstext}
\usepackage{changepage}

% Redefine theorem style

\newtheoremstyle{mytheoremstyle} % name
    {\topsep}   % Space above
    {\topsep}   % Space below
    {\itshape}                   % Body font
    {\parindent}                 % Indent amount
    {\bfseries}                  % Theorem head font
    {.}                          % Punctuation after theorem head
    {0.5em}                      % Space after theorem head
    {}                           % Theorem head spec (can be left empty, meaning ‘normal’)

\theoremstyle{mytheoremstyle}
\newtheorem{theorem}{Theorem}[chapter] 

% HACKING \adjustwidth
\usepackage{etoolbox}
\makeatletter
\apptocmd\adjustwidth{\@inlabelfalse\@newlistfalse}
\makeatother

\begin{document}
\lipsum[1-1]
\begin{theorem}
   This theorem looks correct, but I haven't applied any indentation. 
   It follows the indentation of the document.
\end{theorem}
\lipsum[1-1]
\begin{adjustwidth}{.6cm}{.6cm}
\begin{theorem}
   This theorem has had indentation applied and the result is with similar
   spacing above and below it as in previous theorem.
\end{theorem}
\end{adjustwidth}
\lipsum[1-1]
\end{document}

Blockquote


Update

I have looked a little deeper in the matter, and it appears that this "feature" (misbehavior?) of the theorem environment from package amsthm can be explained by the fact that amsthm uses \trivlist but does not use a standard \item (or rather \@item). A macro \deferred@thm@head takes its place and is lacking some conditional test that is done by the regular \@item: there is no \if@noparitem \@donoparitem \else ... part.

Here is the original:

\def\deferred@thm@head#1{%
  \if@inlabel \indent \par \fi % eject a section head if one is pending
  \if@nobreak
    \adjust@parskip@nobreak
  \else
    \addpenalty\@beginparpenalty
    \addvspace\@topsep
    \addvspace{-\parskip}%
  \fi
  \global\@inlabeltrue
  \everypar\dth@everypar
  \sbox\@labels{\normalfont#1}%
  \ignorespaces
}

Redefining it to be, on the model of the LaTeX kernel \@item :

\def\deferred@thm@head#1{%
\if@noparitem
  \@noparitemfalse
\else
  \if@inlabel \indent \par \fi % eject a section head if one is pending
  \if@nobreak
    \adjust@parskip@nobreak
  \else
    \addpenalty\@beginparpenalty
    \addvspace\@topsep
    \addvspace{-\parskip}%
  \fi
  \global\@inlabeltrue
\fi
  \everypar\dth@everypar
  \sbox\@labels{\normalfont#1}%
  \ignorespaces
}

I observe that with the patched macro there will be no extra blank line if the theorem environment is used as the very first thing in an \item. The patch effect actually even suppresses the default vertical spaces added by theorem, all vertical space responsability falls upon the shoulders of the surrounding list, if there is one (in the case of adjustwidth, that means basically no extra vertical space). Thus this is only a proposal, but it allows to delegate entirely to the surrounding list environment the setting for vertical spacing. And we can then control via the list environment the left and right margin, etc...

As no extra blank line arises from a standard theorem environment following an \item in a list, this feature of amsthm appears to be a mis-behavior.