3

I want to define a new environment ends with a $\omega$ in newline. But environment like displaymath already start a newline after itself, so I do not start a newline in this case. That is, start a newline only after normal text but not environment. How to make it?

The original definition is as following which starts a newline after environment also.

\newenvironment{note}{%
\noindent
\textsc{Note}
\vskip\medskipamount % or other desired dimension
\leaders\vrule width \textwidth\vskip0.4pt % or other desired thickness
\vskip\medskipamount % ditto
\nointerlineskip
}{\mbox{}~\newline\mbox{} \hfill$\Omega$\newline}

As suggested by Peter Grill, I define a \smartsmallskip. And as suggested by David, I change the \newline to \par.

\def\smartsmallskip{\par
  \ifdim\lastskip>0pt \else \smallskip\fi
}

\newenvironment{note}{%
\noindent
\textsc{Note}
\vskip\medskipamount % or other desired dimension
\leaders\vrule width \textwidth\vskip0.4pt % or other desired thickness
\vskip\medskipamount % ditto
\nointerlineskip
}{\smartsmallskip\hfill$\Omega$\par}

Is there still some question I should take care of?

9
  • 1
  • @PeterGrill Thanks! it does. Should I delete this post? Feb 26, 2014 at 2:02
  • 1
    why \newline and the blank lines from\mbox{}~ rather than \par and vertical space? or better a definition using \newtheorem or similar? This version will have very strange behaviour near a page break. Feb 26, 2014 at 2:02
  • 1
    it's better to use a list environment (as used by \newtheorem) as that takes care of things, as is, there is not control over the space before Note the page could break after the heading before the environment contents (or after the leaders) and the spacing between the rule and first line of text is going to be rather variable due to the \nointerlineskip (which means it will be different whether or not there is a capital letter or accent on the first line of content) the final \newline should be a \par (most likely). Feb 26, 2014 at 2:32
  • 1
    @EdenHarder Don't forget that in LaTeX there is \addvspace, so \addvspace{\smallskipamount} is what you need instead of \smartsmallskip
    – egreg
    Feb 26, 2014 at 7:54

1 Answer 1

2

This should do what you want; instead of a \smallskip before the last line, I have used a strut next to the Omega (actually, I think there shouldn't be an additional space and the symbol should go at the end of the last line). The line shouldn't be detached from the heading and the body thanks to \nopagebreak, the same for the last line.

\documentclass{article}
\usepackage{lipsum}

\newenvironment{note}
  {\par\vspace{\topsep}%
   \noindent\textsc{Note}\par\nopagebreak
   \medskip
   \hrule
   \nopagebreak
   \medskip}
  {\par\skip0=\lastskip\nopagebreak
   \hspace*{\fill}\mbox{\ifdim\skip0>0pt \else\rule{0pt}{2ex}\fi$\Omega$}\par
   \vspace{\topsep}}
    \begin{document}


\lipsum[1]

\begin{note}
\lipsum*[2]
\end{note}

\lipsum[3]

\end{document}

enter image description here

2
  • Could you explain about \mbox{\ifdim\skip0>0pt \else\rule{0pt}{2ex}? Thanks a lot! Feb 26, 2014 at 12:22
  • @EdenHarder That's for adding the strut only if the previous material doesn't end with a skip (such as after a math display).
    – egreg
    Feb 26, 2014 at 12:45

You must log in to answer this question.

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