# Putting a vertical line next to an exercise

I'm working with an existing environment (exercise) provided by the svmono documentstyle (springer monographs) and sometimes it is unclear where an exercise ends and the next paragraph begins.

To solve this, I am trying to add a vertical line to the left of the text. I am using the framed package for this, using a modification of leftbar. I'm not quite sure where I got this from, but a problem I have is that the bar extends about a line too high and to low on either side of the exercise. Thus the exercise now takes up too much vertical space. Here is an example using amsthm for the environment rather than the provided version.

\documentclass{article}

\usepackage{amsthm}
\newtheorem{exercise}{Exercise}

\usepackage{framed}

\renewenvironment{leftbar}[1][\hsize]
{%
\def\FrameCommand
{%
{\hspace{-0.5ex}\vrule width 0.5pt}%
\hspace{0ex}%must no space.
\fboxsep=\FrameSep%
}%
}
{\endMakeFramed}

\let\oldexercise\exercise
\let\oldendexercise\endexercise
\def\exercise{\begingroup \begin{leftbar}\oldexercise}
\def\endexercise{\oldendexercise \end{leftbar}\endgroup}

\begin{document}
some text
\begin{exercise}
here is exercise 1.
\end{exercise}
more text
\end{document}


Is there a way to modify this so that the bar does not cause the environment to take up extra vertical space? (alternately - since this may be an XY problem - is there a better alternative to make the exercise clearly distinct from the rest of the text?)

• Could you post a fully compilable, yet minimal, code, that we can play with? – Bernard Jun 12 '16 at 1:08
• @bernard - A bit hard because it relies on an existing environment, but I'll build one. Give me a few minutes – Joel Jun 12 '16 at 1:14
• OK. B.t.w., if the exercise environment is based on amsthm, you might use a customised version of \qedhere or/and a \small font size. – Bernard Jun 12 '16 at 1:19
• @Bernard Got the example in. It uses amsthm for the sample. I don't want to play with font sizes/shapes. – Joel Jun 12 '16 at 1:23

I propose a solution based on mdframed, which is easy to customise. Hope it's close to what you want:

\documentclass{article}
\usepackage{amsthm}
\usepackage{mdframed}
\usepackage{lipsum}

\newmdtheoremenv[linewidth=0.5pt, topline=false, bottomline=false, rightline=false,%
leftmargin=0pt, innerleftmargin=0.4em, rightmargin=0pt, innerrightmargin=0pt, innertopmargin=-5pt ,%
innerbottommargin=3pt, splittopskip=\topskip, splitbottomskip=0.3\topskip, %
skipabove=0.6\topsep]%
{exercise}{Exercise}%

\begin{document}

\lipsum[11]
\begin{exercise}
Here is exercise 1. You must answer the following question:  why is it that
$1 + 1 = 2$%
\end{exercise}
more text

\end{document}