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.

I've created custom environment with these commands:

\usepackage{relsize}
\newcounter{annotation}
\def\theannotation{\arabic{annotation}}
\newenvironment{annotation}
    {\refstepcounter{annotation}\noindent\begin{smaller}
        \makebox[1.5cm][l]{NOTE \theannotation}}
    {\end{smaller}}

One thing is still missing here - vertical spaces before, and after it. I can add \vspace, but using two consecutive annotations doubles \vspace (after first and before second annotation).

So my question is: how to create vertical space before and after custom environment, so that it doesn't double itself when using with other vertically spaced environments (e.g. description).

Example usage:

\begin{annotation}
    \lipsum[1]
\end{annotation}
\begin{description}
    \item[aaa] asdfasdfasdf
\end{description}
\begin{annotation}
    \lipsum[1]
\end{annotation}

I've tried lockstep's solution, wchich worked fine for empty document, but fails in my document. I've found, that simply adding line of text causes error. Sample code:

\documentclass[twoside,titlepage]{article}
\usepackage{relsize}
\newcounter{annotation}
\newenvironment{annotation}
    {\addvspace{\baselineskip}\refstepcounter{annotation}
        \noindent\begin{smaller}
        \makebox[1.5cm][l]{UWAGA \theannotation}}
    {\end{smaller}\addvspace{\baselineskip}}
\usepackage{lipsum}
\begin{document}
    fail                % remove this line, and everything works
    \begin{annotation}
        \lipsum[1]
    \end{annotation}
    \begin{annotation}
        \lipsum[1]
    \end{annotation}
\end{document}

Error msg: Something's wrong--perhaps a missing \item., l.12 \begin{annotation}


solved using this \par is needed before \addvspace{\baselineskip}

share|improve this question
add comment

1 Answer

up vote 12 down vote accepted

You are looking for \addvspace.

\documentclass{article}

\usepackage{relsize}
\newcounter{annotation}
% \def\theannotation{\arabic{annotation}}% superfluous with \newcounter
\newenvironment{annotation}
    {\par\addvspace{\baselineskip}\refstepcounter{annotation}\noindent\begin{smaller}
        \makebox[1.5cm][l]{NOTE \theannotation}}
    {\end{smaller}\par\addvspace{\baselineskip}}

\usepackage{lipsum}

\begin{document}

\begin{annotation}
    \lipsum[1]
\end{annotation}
\begin{description}
    \item[aaa] asdfasdfasdf
\end{description}
\begin{annotation}
    \lipsum[1]
\end{annotation}

\end{document}

enter image description here

EDIT: Added missing \par before \addvspace.

share|improve this answer
    
works, thanks again, I solved second problem by adding \par before \addvspace{\baselineskip} –  Soul Reaver Feb 15 '12 at 11:02
add comment

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.