1

In a memoir class document, I would like to display a figure and a marginfigure next to each other but I need the top of the marginfigure at the same vertical level as the figure next to it.

When I try the following

\documentclass{memoir}
\usepackage{graphicx}
\begin{document}
\begin{figure}[!ht]
    \includegraphics[width=\columnwidth]{example-image-a}
    \caption{Figure along text}
\end{figure}
\begin{marginfigure}
    \includegraphics[width=\marginparwidth]{example-image-b}
    \caption{Margin figure}
\end{marginfigure}
\end{document}

I end up with the top of the marginfigure at a lower level than the top of the figure:

enter image description here

When I invert their order in the code, the opposite occurs:

enter image description here

Is it possible to have the top of both floats at the same vertical level?

  • why you not enclose images in the same float environment which has locally increased \textwidth. for example with help of the changepage package? – Zarko Dec 7 '18 at 18:58
  • The basic problem here is that the marginfigure is aligned vertically relative to the text in the document, not to the float. Put some text in the MWE above and below the floats to make it clearer what is going on, and also try \begin{figure}[!t] for example. As @Zarko said, the only general solution is to combine both graphics into a single float. – alephzero Dec 7 '18 at 21:43
1

let me elaborate my comment ...

the package memoir has integrated functionality of the changepage package. for use of its macro adjustwidth for locally change the text width in two side documents is advisable to use the option strict which will push smaller image to margin of a page:

\documentclass[strict]{memoir}
\usepackage[export]{adjustbox} % for align images in table, ...
\usepackage{tabularx}

%---------------- show page layout. don't use in a real document!
\usepackage{showframe}
\renewcommand\ShowFrameLinethickness{0.15pt}
\renewcommand*\ShowFrameColor{\color{red}}
%---------------------------------------------------------------%

\begin{document}
    \begin{figure}[htb]
\begin{adjustwidth*}{}{-\dimexpr\marginparsep+\marginparwidth\relax}
\setlength\tabcolsep{0pt}
    \begin{tabularx}{\linewidth}{X @{\hspace{\marginparsep}}p{\marginparwidth}}
\includegraphics[width=\linewidth,valign=t]{example-image-a}
    \caption{Figure along text}
    &   \includegraphics[width=\linewidth,valign=t]{example-image-b}
        \caption{Margin figure}
    \end{tabularx}
\end{adjustwidth*}
    \end{figure}
\end{document}

enter image description here

(red lines indicate page layout)

why your approach cannot work, see alephzero's comment above.

  • This works great and I did not know about most of what you explained. However, what would I need to do to have another marginfigure directly below the "B" marginfigure? – jrojasqu Dec 10 '18 at 23:53
  • @jrojasqu, you put in comment new question :-). this is not well visible to others which eventually would like to answer you. please edit your question and add new request or (even better) ask new question. also explain how this second image should be aligned (simply below "B"?). – Zarko Dec 10 '18 at 23:59
  • A new question it is then :) – jrojasqu Dec 11 '18 at 0:00
  • 1
    @jrojasqu, if the image is only below "B" and hasn't special requirement for align, than just add one more image in the second column, for example:& \includegraphics[width=\linewidth,valign=t]{example-image-b} \caption{Margin figure B} \medskip \includegraphics[width=\linewidth,valign=b]{example-image-c} \caption{Margin figure C} – Zarko Dec 11 '18 at 0:10
  • Wow, it's that easy... I was setting up another table inside the first table just to add more marginfigures below "B" and could not work it out properly. Never crossed my mind to simply skip the line... Thanks a lot! – jrojasqu Dec 11 '18 at 0:18

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.