# Vertical spacing of framed environment

Here is an MWE that shows the problem:

\documentclass{article}
\usepackage{framed}
\setlength{\FrameSep}{3pt}
\setlength{\parindent}{0pt}
\begin{document}
\fbox{Foo}

\fbox{Foo}

\begin{framed}
Foo
\end{framed}
\begin{framed}
Foo
\end{framed}
\end{document}


The framed package puts more spacing around its argument than \fbox does. I can reduce the "cell padding" to its default by fixing \FrameSep but I don't know how to fix the horizontal spacing outside the frame. The documentation is... sparse. I don't read TeX fluently enough to understand framed.sty but it's a fairly small file, so I expect is it easy to do...

-

You can try mdframed.sty, extending the package framed.sty. You have a better control of parameters. Look at the documentation for all the options (mdframed-doc-en.pdf) mdframed. The parameters to adjust the text inside the box are : innerleftmargin,innerrightmargin, innertopmargin etc. and you have a macro \mdfsetup to set all these options.

\documentclass{article}
\usepackage{mdframed}
\setlength{\parindent}{0pt}
\begin{document}
\fbox{Foo}

\fbox{Foo}

\begin{mdframed}
Foo
\end{mdframed}
\begin{mdframed}
Foo
\end{mdframed}
\end{document}


-
Very good advice to use mdframed instead! Perhaps also add a link to the package on CTAN in your answer. That package is pretty new, perhaps it's not included in everyone's installation. –  Stefan Kottwitz Mar 5 '11 at 14:01
@Stefan: Yes, you are right but I'm a new user and I have not good reflexes. I hope the link is correct ! –  Alain Matthes Mar 5 '11 at 14:11
the link is correct! We usually choose package links this way: http://ctan.org/pkg/mdframed. It's easy to remember and to guess, furthermore it doesn't depend on the path in the tex archive. At least we hope these pkg links work longer. –  Stefan Kottwitz Mar 5 '11 at 14:25
I think the reason I wasn't using mdframed was because it wasn't installed! I'm more confident than I used to be ab)out installing stuff myself, so I've installed it, and it works perfectly. Word of warning: the style=1 option has to be a package option. It doesn't work if you call it in \mdfsetup. (It makes all your frames disappear.) –  Seamus Mar 5 '11 at 14:33

framed adds spacing according to \topsep. Try

\setlength{\topsep}{0pt}


to see the effect. To avoid effects to the rest of the document, adjust it locally, i.e. using your own framed-like environment which sets that length. Within your own environment you could call:

\begin{MakeFramed}{%
\setlength{\topsep}{0pt}%

Also, setting topsep inside the environment doesn't seem to work... (And I don't really understand what \advance\hsize-\width is doing) –  Seamus Mar 5 '11 at 13:32
@Seamus: framed does a lot more than \fbox, internally. If I want it to act the same like \fbox, I would just use the latter. You could redefine \fb@afterframe, to insert negative space after the box, though it would affect following text. –  Stefan Kottwitz Mar 5 '11 at 13:57
I think is dangerous to redefine \fb@afterframe. Perhaps, we can (re)define \FrameHeightAdjust (height of frame above baseline at top of page). One remark : framed.sty uses fbox \providecommand\FrameCommand{% \setlength\fboxrule{\FrameRule}\setlength\fboxsep{\FrameSep}% \fbox} \@ifundefined{FrameRule}{\newdimen\FrameRule \FrameRule=\fboxrule}{} \@ifundefined{FrameSep} {\newdimen\FrameSep \FrameSep =3\fboxsep}{} –  Alain Matthes Mar 5 '11 at 14:19