# Problem with the marginfit package and margin changes

I am using the memoir package and make heavy use of margin notes (with \marginpar). I had a lot of issues with the placement of the notes until I discovered the very recent package marginfit, which does a significantly better job than marginfix and others.

However, the package seems to break memoir's \adjustwidth functionality, in particular preventing me from using full-width figures (on odd pages only!). Here is an example of a full-width figure without marginfit: and here is what happens as soon as I load marginfit:

The code is as follows.

\documentclass[twoside,11pt,final]{memoir}

\usepackage{lipsum}

\usepackage{marginfit}

\newlength{\fullwidthlen}
\setlength{\fullwidthlen}{\marginparwidth}
\newenvironment{fullwidth}{%
}{%
}

\begin{document}

\begin{figure}
\begin{fullwidth}
\rule{\linewidth}{1em}
\end{fullwidth}
\end{figure}

\marginpar{Donec vehicula augue eu neque.}

\lipsum[1]

\marginpar{Donec varius orci eget risus.}

\end{document}


The way \adjustwidth works is

\newenvironment{adjustwidth}[2]{%
\begin{list}{}{%
\topsep\z@%
\listparindent\parindent%
\parsep\parskip%
\@ifmtarg{#1}{\setlength{\leftmargin}{\z@}}%
{\setlength{\leftmargin}{#1}}%
\@ifmtarg{#2}{\setlength{\rightmargin}{\z@}}%
{\setlength{\rightmargin}{#2}}%
}
\item[]}{\end{list}}


Does anyone have ideas about how this problem could be fixed?

• Well it get even worse of you start this MWE with test \newpage, then it also moves the lorem ipsum – daleif Jun 6 '18 at 16:05
• Also which exact problems did you have with \marginpar? memoir has some extra tricks users tend to forget. Memoir does not address, problem 2, but the placement fixable using \strictpagecheck. I have no idea what that package is doing, and why a list inside a float can make everything behave so badly – daleif Jun 6 '18 at 16:11
• @daleif I use \marginpar to place bibliographic references in the margin next to every \cite. Even with \strictpagecheck, the \marginpars would often appear on the wrong margin, and it was difficult to manage the placement of the \marginpars near the bottom of the page, etc. Loading marginfit immediately gets rid of all these problems for me. – sps Jun 6 '18 at 16:22
• I would like to see an example of a marginpar not in the right margin under strict (it takes a few compilations for it to settle) – daleif Jun 6 '18 at 16:54

The problem is that \adjustwidth enlarges the outputbox. To my understanding, this is not the correct behavior, but maybe it is not possible to do otherwise.

You can fix the problem with the following code in the preamble after loading marginfit.

\makeatletter
\let\my@makecol\marginfit@makecol
\def\marginfit@makecol{%
\my@makecol%
\wd\@outputbox\columnwidth%
}
\makeatother


I will update marginfit to handle that properly soon.