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 am using the code from margin-floats-and-hyperlinks. It works nicely, however the figure generated is not left aligned in the margin as the caption below it is. I also tried \raggedright as suggested in align-figure-to-the-right-with-raggedleft.

Figure is not left aligned in the margin

MWE

\documentclass{report}
\usepackage{geometry}
\geometry{
  showframe=true,
  includeheadfoot,
  includemp,
  marginparwidth=3.5cm,
  marginparsep=1.5em,
  hmargin={3cm,1.5cm},
  vmargin={2cm,2cm},
  headsep=2ex,
  footskip=3ex
}
%
%http://tex.stackexchange.com/questions/27348/margin-floats-and-hyperlinks
\usepackage{placeins}

\makeatletter
% Margin float environment
\newsavebox{\@tufte@margin@floatbox}
\newenvironment{@tufte@margin@float}[2][-1.2ex]%
  {\FloatBarrier% process all floats before this point so the figure/table numbers stay in order.
  \begin{lrbox}{\@tufte@margin@floatbox}%
  \begin{minipage}{\marginparwidth}%
    \def\@captype{#2}%
    \hbox{}\vspace*{#1}%
    \noindent%
  }
  {\end{minipage}%
  \end{lrbox}%
  \marginpar{\usebox{\@tufte@margin@floatbox}}%
  }

% Margin figure environment
\newenvironment{marginfigure}[1][-1.2ex]%
  {\begin{@tufte@margin@float}[#1]{figure}
  }
  {\end{@tufte@margin@float}}

% Margin table environment
\newenvironment{margintable}[1][-1.2ex]%
  {\begin{@tufte@margin@float}[#1]{table}
  }
  {\end{@tufte@margin@float}}

\makeatother

\begin{document}
  \begin{marginfigure}
    %\raggedright
    \rule{3cm}{2cm}
    \caption{A long caption so that we get at least two lines}
  \end{marginfigure}
\end{document}
share|improve this question
add comment

1 Answer

up vote 7 down vote accepted

You have a spurious space in the definition of marginfigure and margintable:

% Margin figure environment
\newenvironment{marginfigure}[1][-1.2ex]%
  {\begin{@tufte@margin@float}[#1]{figure}% <--- added '%'
  }
  {\end{@tufte@margin@float}}

% Margin table environment
\newenvironment{margintable}[1][-1.2ex]%
  {\begin{@tufte@margin@float}[#1]{table}% <--- added '%'
  }
  {\end{@tufte@margin@float}}

enter image description here

As a reference, see What is the use of percent signs (%) at the end of lines?. Alternatively, you could insert an \ignorespaces at the start of the environments.

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.