Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

The user 'egreg' recently helped me to suppress vertical space between theorem heads and enumitem environments (such as itemize; see the link below). I now have a similar problem: When a proof environment starts with an itemize, there is too much vertical space. How can the proof environment be redefined such that this space is (at least party) suppressed?

Ideally, it should be a "clean" solution, so that one can type \begin{proof} followed by \begin{itemize} and no complicated commands in-between.

By redefining the proof environment as a theorem, one could circumvent the problem, but how can the q.e.d. symbol be nicely placed? Not sure if that's a good approach.

\documentclass{scrartcl}

\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage[american]{babel}
\usepackage{amsmath}
\usepackage{amsthm}
\usepackage{etoolbox}
\usepackage{enumitem}

% theorems
\newif\ifstarttheorem
\newtheoremstyle{mythmstyle}%
{0.5em}%
{0.5em}%
{}% 
{}% 
{\sffamily\bfseries\global\starttheoremtrue}% 
{}% 
{\newline}% 
{\thmname{#1}\ \thmnumber{#2}\ \thmnote{(#3)}}% 
\theoremstyle{mythmstyle}% 

% proofs
\renewcommand*\proofname{Proof}
\makeatletter% q.e.d. adjustment (posted by ???)
\renewenvironment{proof}[1][\proofname]{\par
  \pushQED{\qed}%
  \normalfont\topsep2\p@\@plus2\p@\relax
  \trivlist
\item[\hskip\labelsep
  \sffamily\bfseries #1]\mbox{}\hfill\\*\ignorespaces
}{%
  \popQED\endtrivlist\@endpefalse
}
\makeatother

% suppress vertical spacing (for itemize) when newtheorems start with an environment
% see http://tex.stackexchange.com/questions/60001/nested-enumerate-enumitem-interferes-with-suppressing-vertical-space-after-the
\makeatletter
\preto\itemize{%
  \if@inlabel
    \ifstarttheorem
      \mbox{}\par\nobreak\vskip\glueexpr-\parskip-\baselineskip+0.3em\relax\hrule\@height\z@
      \global\starttheoremfalse
    \fi
  \fi}
\preto\enditemize{\global\starttheoremfalse}
\makeatother

% document
\begin{document}
Let's prove something:
\begin{proof}
  \begin{align*}
    x=y,\quad y=z\quad\Rightarrow\quad x=z.
  \end{align*}
\end{proof}
Here a nicer vertical spacing:
\begin{proof}
  Just some text:
  \begin{align*}
    x=y,\quad y=z\quad\Rightarrow\quad x=z.
  \end{align*}
\end{proof}
Here a version with itemize:
\begin{proof}
  \begin{itemize}
    \item $x=y,\quad y=z\quad\Rightarrow\quad x=z.$
  \end{itemize}
\end{proof}
\end{document}
share|improve this question

1 Answer 1

up vote 3 down vote accepted

You can try the following. Here the environment proof gets a new flag \starttheoremtrue and the name of the environment is saved inside the command \mycurrenvir.

\documentclass{scrartcl}

\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage[american]{babel}
\usepackage{amsmath}
\usepackage{amsthm}
\usepackage{etoolbox}
\usepackage{enumitem}

% theorems
\newif\ifstarttheorem
\newtheoremstyle{mythmstyle}%
{0.5em}%
{0.5em}%
{}% 
{}% 
{\sffamily\bfseries\global\starttheoremtrue}% 
{}% 
{\newline}% 
{\thmname{#1}\ \thmnumber{#2}\ \thmnote{(#3)}}% 
\theoremstyle{mythmstyle}% 

% proofs
\renewcommand*\proofname{Proof}
\makeatletter% q.e.d. adjustment (posted by ???)
\renewenvironment{proof}[1][\proofname]{\par
  \pushQED{\qed}%
  \normalfont\topsep2\p@\@plus2\p@\relax
  \trivlist
\item[\hskip\labelsep
  \sffamily\bfseries #1]\gdef\mycurrenvir{proof}\global\starttheoremtrue\mbox{}\hfill\\*\ignorespaces
}{%
 \gdef\mycurrenvir{\relax}
  \popQED\endtrivlist\@endpefalse
}
\makeatother

% suppress vertical spacing (for itemize) when newtheorems start with an environment
% see http://tex.stackexchange.com/questions/60001/nested-enumerate-enumitem-interferes-with-suppressing-vertical-space-after-the
\makeatletter
\preto\itemize{%
  \if@inlabel
    \ifstarttheorem
      \mbox{}\par\nobreak\vskip\glueexpr-\parskip-\baselineskip+0.3em\relax\hrule\@height\z@
      \global\starttheoremfalse%
    \fi%
  \fi%
 \def\tempa{proof}%
 \ifx\tempa\mycurrenvir
    \ifstarttheorem
      \mbox{}\par\nobreak\vskip\glueexpr-\parskip-\baselineskip+0.3em\relax\hrule\@height\z@
      \global\starttheoremfalse%
    \fi%
 \fi%
}
\preto\enditemize{\global\starttheoremfalse}
\makeatother

% document
\begin{document}
Let's prove something:
\begin{proof}
  \begin{align*}
    x=y,\quad y=z\quad\Rightarrow\quad x=z.
  \end{align*}
\end{proof}
Here a nicer vertical spacing:
\begin{proof}
  Just some text:
  \begin{align*}
    x=y,\quad y=z\quad\Rightarrow\quad x=z.
  \end{align*}
\end{proof}
Here a version with itemize:
\begin{proof}
  \begin{itemize}
    \item $x=y,\quad y=z\quad\Rightarrow\quad x=z.$
  \end{itemize}
\end{proof}
\end{document}

enter image description here

share|improve this answer
    
works nicely with itemize, even using \qedhere. but with enumerate there's still a big gap between the heading and the first item (and \qedhere isn't the cause). –  barbara beeton Aug 11 '12 at 16:04
    
Thanks a lot, Marco. @Barbara: Just redefine enumerate (as for itemize) and it works –  Marius Hofert Aug 11 '12 at 16:11
    
Marco, if a proof environment is directly followed by an align environment, do you know how to suppress the space in this situation? –  Marius Hofert Aug 11 '12 at 16:16
    
@MariusHofert: I would use the same redefinition. –  Marco Daniel Aug 11 '12 at 18:20
    
Thanks Marco. It's a bit difficult to understand since I do not see how the trick for the itemize environment can be adapted to an align. If possible, can you give the answer in your answer, please? [I could also file a new question for this] –  Marius Hofert Aug 11 '12 at 20:18

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.