1

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}

enter image description here

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

enter image description here

2 Answers 2

1

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

See https://tex.stackexchange.com/a/102026/161015

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).

And https://tex.stackexchange.com/a/102025/161015

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

z

\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%
            \ignorespaces%  added <<<<<<<<<<<<<<<<<<<       
        }
        {%
        \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
2
  • +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
1

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}

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.