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 have defined an exercise environment which ends with a horizontal rule. I want to have some vertical space between the end of the environment text and the rule. When I try to insert that, the vertical space ends up after (below) the rule instead of before it.

I have tried both \medskip at the beginning of the HorzLine command, and \vspace{5\bigskipamount} before the \HorzLine at the exercise environment, and both don't work.

What's going on?

Here is some code:

\documentclass[a4paper,10pt]{article}
\usepackage[english]{babel}
\usepackage{blindtext}
\usepackage{color}

\definecolor{orange}{rgb}{1,.549,0}

\newcommand{\HorzLine}{\medskip\noindent\textcolor{orange}{\rule{\textwidth}{5pt}}}

\newenvironment{exercise}
{\noindent\small\textbf{Exercise:}}
{\vspace{5\bigskipamount}\HorzLine}

\begin{document}
    \begin{exercise}
        \blindtext
    \end{exercise}
    \blindtext
\end{document}
share|improve this question
1  
Should the title instead be Vertical before horizontal line? –  Peter Grill Sep 26 '11 at 15:01
add comment

3 Answers

up vote 4 down vote accepted

\vspace doesn't take effect until you are in vertical mode. \blindtext probably doesn't end with \par or a blank line, so it's still in horizontal mode when the environment ends. put \par at the beginning of the end code for the environment to force the vertical space above the rule:

{\par\nobreak\vspace{5\bigskipamount}\HorzLine}

EDIT: added \nobreak to prevent a page break just before the \HorzLine.

share|improve this answer
add comment

Simply change \vspace{5\bigskipamount} to \vskip5\bigskipamount solve the problem

share|improve this answer
add comment

You need to leave some whitespace in your code between the \vspace and the \HorzLine:

\newenvironment{exercise}
{\noindent\small\textbf{Exercise:}}
{\vspace{5\bigskipamount}

\HorzLine}

enter image description here

The whitespace changes the mode TeX is in.

share|improve this answer
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.