# Adjusting figures or images in margins

Say I want figures to be placed in the margins. I have the following code which produces:

\documentclass[11pt,twoside,openany]{book}

\usepackage{amsmath,amssymb}
\usepackage{lipsum}
\usepackage[demo]{graphicx}
\usepackage{multicol,calc,etoolbox}
\usepackage{marginnote}
\usepackage{caption}
%-------------------------------------------------------------------------------
\usepackage[centering,marginparwidth=2in]{geometry}
\evensidemargin 1.5in
\oddsidemargin 1.5in
\setlength{\textwidth}{5.5in}
%-------------------------------------------------------------------------------

\newenvironment{exotmp}{%
\begin{list}{}{%
\setlength{\leftmargin}{-1.5in}%
\setlength{\rightmargin}{0pt}%
\setlength{\parfillskip}{0pt plus 2fil}
}%
\item\mbox{}\ignorespaces%
}
{\end{list}\ignorespacesafterend}

\newcommand\MarginFig[4][width=\marginparwidth]{%
\marginpar{\includegraphics[#1]{#2}
\captionof{figure}{#3}
\label{#4}}
}
%To put all marginnotes on the left side only the patch below is implemented
\makeatletter
\patchcmd{\@mn@margintest}{\@tempswafalse}{\@tempswatrue}{}{}
\patchcmd{\@mn@margintest}{\@tempswafalse}{\@tempswatrue}{}{}
\reversemarginpar
\makeatother

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{document}
\chapter{Introduction to Problem Solving}
\lipsum[2]
\section{The Problem-Solving Process and Strategies}
\lipsum[4-7]
\lipsum[5-12]
\begin{exotmp}
\setlength{\columnsep}{0.5cm}
\begin{multicols}{2}
\lipsum[2-9]
\end{multicols}
\end{exotmp}
\MarginFig{pencil}{description for figure one}{fig:test1}
\lipsum[1-3]
\MarginFig{pencil}{description for figure one}{fig:test2}
\end{document}


What is causing the figure not to display correctly and how can this be fixed. I have read this post, How to make all figures float on the outer margins of two-side document?, but haven't been successful in fixing the issue.

PS: On another note, am looking to fix my code above if there are any inconsistences or bad LaTeXing.

-
Can you add a note as to what the purpose of the \patchcmd's is. – Peter Grill Oct 27 '12 at 5:30
@PeterGrill It forces the marginpars to be on the left hand side only but doesn't seem to work in even numbered pages. – azetina Oct 27 '12 at 5:31
But then what is \reversemarginpar for? Also, why is your document not two sided on the first three pages??? Sorry, if these are obvious, this is new territory for me, so trying to learn. – Peter Grill Oct 27 '12 at 5:35
Perhaps you should add a link to tex.stackexchange.com/questions/73102/…, as an explanation of those patches. Again, all new to me. – Peter Grill Oct 27 '12 at 5:38
What input?? I was just trying to learn, not show you the answer!! Now how am I supposed to catch up to @David Carlise??? You should provide a self-answer... I'll go back to distracting Gonalzo then. :-) You sure you don't need to draw arrows from the figures to somewhere on the page ??? :-) I could go for a \tikzmark answer. – Peter Grill Oct 27 '12 at 5:43

Found my mistake:

Instead of \marginpar in

\newcommand\MarginFig[4][width=\marginparwidth]{%
\marginpar{\includegraphics[#1]{#2}
\captionof{figure}{#3}
\label{#4}}
}


It should be:

\newcommand\MarginFig[4][width=\marginparwidth]{%
\marginnote{\includegraphics[#1]{#2}
\captionof{figure}{#3}
\label{#4}}
}


Simple mistake on my part and of course thanks to @PeterGrill's annoying questions was I able to solve my problem. :-)

-
I personally think that these kind of questions should NOT be closed as this is an easy mistake to made -- I think I actually made it a few weeks ago when I first attempted to place text in the margin. So if others make the same mistake, finding an "Duh" answer such as this is helpful. – Peter Grill Oct 27 '12 at 5:54
Hey, but you forgot to point out that the only reason you were able to see this is because I kept asking annoying questions which made you look at the code again. :-) – Peter Grill Oct 27 '12 at 5:55
@PeterGrill lol :-) Sure thanks to you of course. – azetina Oct 27 '12 at 5:58