# Marginfigure image in tufte-handout is off center when using vertical alignment option

When using the \includgraphics command (under the graphicx package) in the marginfigure environment, the image is slightly off center to the right, but only when using the vertical alignment option.

\documentclass{tufte-handout}

\usepackage{graphicx}
\geometry{showframe}

\begin{document}

\begin{marginfigure}[-0.5in]
\includegraphics[width=\textwidth]{bb_navy.jpg}
\end{marginfigure}

\end{document}


Without the vertical alignment, the image is centered as expected.

The environment defined by tufte-handout for inserting figures and other floats in the margin should be fixed by adding a \ignorespaces after \noindent.

It's a primitive feature of TeX's line breaking algorithm that glue (including glue from white space) is discarded at the beginning of the line. But \noindent starts the paragraph already so the following space token produces glue that is not discarded,(as it doesn't follow a linebreak).

Whenever you use \noindent (or \indent) at the end of a macro with arguments, it's good rule to add \ignorespaces

\documentclass{tufte-handout}

\usepackage{graphicx}
\geometry{showframe}

\makeatletter

\renewenvironment{@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}%
\@tufte@caption@font%
\def\@captype{#2}%
\hbox{}\vspace*{#1}%
\@tufte@caption@justification%
\@tufte@margin@par%
\setlength{\parindent}{0.0pc}%
\noindent%
}
{%
\end{minipage}%
\end{lrbox}%
\marginpar{\usebox{\@tufte@margin@floatbox}}%
}

\makeatother

\begin{document}

\begin{marginfigure}[-0.5in]
\includegraphics[width=\linewidth]{example-image-a}
\end{marginfigure}

\begin{marginfigure}% [-0.5in]
\includegraphics[width=\linewidth]{example-image-c}
\end{marginfigure}

\end{document

• +1 Great, you found the culprit and an explanation!
– DG'
May 30, 2021 at 19:11
• Yes, this is the "fix." Thank you for the help!
– Roy
May 30, 2021 at 20:27

You can fix that by moving the \noindent directly to the beginning of the minipage:

\documentclass[nobib]{tufte-handout}

\usepackage{graphicx}
\geometry{showframe}

\makeatletter
\renewenvironment{@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}%
\noindent% <-- MOVE HERE
\@tufte@caption@font%
\def\@captype{#2}%
\hbox{}\vspace*{#1}%
\@tufte@caption@justification%
\@tufte@margin@par%
}
{\end{minipage}%
\end{lrbox}%
\marginpar{\usebox{\@tufte@margin@floatbox}}%
}
\makeatother

\begin{document}

\begin{marginfigure}[-.5in]
\includegraphics[width=\textwidth]{example}
\end{marginfigure}

\end{document}