1

If I run the following code

\documentclass[11pt]{article}
\usepackage[T1]{fontenc}
\usepackage{color}
\usepackage{amsmath}
\usepackage{amsthm}
\def\myproof#1{{\color{blue}\begin{proof}#1 \end{proof}}}

\begin{document}
\begin{enumerate}
  \item 1
  \myproof{sdf}
  \item Thisis Thisis This is This is This is This is This is This is This is This.
  \myproof{sdf}
\end{enumerate}
\end{document}

Then, I would get

enter image description here

which has a bad vertical spacing right above the second Proof.

I can solve this problem by adding % or \leavevmode right after This.

But is there any way I can prevent this in the first place by changing the definition of \myproof?

4
  • By inserting \leavevmode into the definition of \myproof? (side note \textcolor instead of \color might work better although I didn't try. different syntax however)
    – user202729
    Commented Aug 7, 2022 at 3:32
  • @user202729 Both of them do not work in this case...
    – user182849
    Commented Aug 7, 2022 at 3:48
  • You could place a % (comment) character right after This..
    – Mico
    Commented Aug 7, 2022 at 4:11
  • 1
    \unskip{\color{blue}... Commented Aug 7, 2022 at 8:21

1 Answer 1

3

You need \par in front of \color{blue}.

What happens in your example is that the space coming from the endline is followed by {\color{blue}\begin{proof}...} and the \par that's issued by \begin{proof} (actually by \trivlist, but it's not important) cannot remove it. So a line consisting of just one space is built.

This can be seen by the following example, where you see that masking the endline with % removes the spurious line.

\documentclass[11pt]{article}
\usepackage[T1]{fontenc}
\usepackage{color}
\usepackage{amsmath}
\usepackage{amsthm}
\def\myproof#1{{\color{blue}\begin{proof}#1 \end{proof}}}

\begin{document}
\begin{enumerate}
  \item 1
  \myproof{sdf}
  \item Thisis Thisis This is This is This is This is This is This is This is This.%
  \myproof{sdf}
  \item Thisis Thisis This is This is This is This is This is This is This is This.
  \myproof{sdf}
\end{enumerate}
\end{document}

enter image description here

If we modify it as

\documentclass[11pt]{article}
\usepackage[T1]{fontenc}
\usepackage{color}
\usepackage{amsmath}
\usepackage{amsthm}

\newcommand\myproof[1]{\par{\color{blue}\begin{proof}#1 \end{proof}}}

\begin{document}
\begin{enumerate}
  \item 1
  \myproof{sdf}
  \item Thisis Thisis This is This is This is This is This is This is This is This.%
  \myproof{sdf}
  \item Thisis Thisis This is This is This is This is This is This is This is This.
  \myproof{sdf}
\end{enumerate}
\end{document}

you can see that the % is no longer necessary.

enter image description here

My preferred way would be

\newenvironment{blueproof}{\par\color{blue}\proof}{\endproof}

using

\begin{enumerate}
  \item 1
  \begin{blueproof}
  sdf
  \end{blueproof}
  \item Thisis Thisis This is This is This is This is This is This is This is This.
  \begin{blueproof}
  sdf
  \end{blueproof}
\end{enumerate}
\end{document}
4
  • Perfect! thanks!
    – user182849
    Commented Aug 7, 2022 at 13:31
  • @user182849 I'd much prefer the environment form I added.
    – egreg
    Commented Aug 7, 2022 at 13:38
  • May I ask you why?
    – user182849
    Commented Aug 7, 2022 at 13:40
  • 1
    @user182849 Cleaner to input if the proof is long.
    – egreg
    Commented Aug 7, 2022 at 13:51

You must log in to answer this question.

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