# Tufte-Latex: How do I stop marginfigure from inserting inline space?

I want to use marginfigure, but it is inserting space inline. Check out my minimal example:

documentclass{tufte-book}

\begin{document}
Hello\begin{marginfigure}$2+2=4$\end{marginfigure}I'm new here.

\end{document}


As you can see, the "Hello I'm new here" is two different lines--I want a single line. Of course, one "solution" is to simply move the marginfigure; however, this is not an option for me.

-

The culprit appears to be the \FloatBarrier command (provided by the placeins package). If we remove the \FloatBarrier command from the code that generates the marginfigure, then no space is inserted:

\documentclass{tufte-book}

% Remove \FloatBarrier from marginfigure definition
% to prevent unwanted spaces.
\makeatletter% so we can use @ commands
\renewenvironment{@tufte@margin@float}[2][-1.2ex]{%
%\FloatBarrier% removed because it adds unwanted white space
\begin{lrbox}{\@tufte@margin@floatbox}%
\begin{minipage}{\marginparwidth}%
\@tufte@caption@font
\def\@captype{#2}%
\hbox{}\vspace*{#1}%
\@tufte@caption@justification
\@tufte@margin@par
\noindent
}{%
\end{minipage}%
\end{lrbox}%
\marginpar{\usebox{\@tufte@margin@floatbox}}%
}
\makeatother% restore meaning of @

\begin{document}

Hello\begin{marginfigure}$2+2=4$\end{marginfigure}I'm new here.

\end{document}

-
Thanks! This helped a lot! – Bart Snapp Jan 15 '13 at 20:18
To make this work in Lyx, simply remove \makeatletter% so we can use @ commands and \makeatother% restore meaning of @ from the code and use everything else in between inside Document>Settings>LaTeX Preamble for Lyx. – Black Milk Oct 30 '13 at 0:13