# Help with \sidepar and position - with MVC

I have a problem with a sidepar in the memoir class. I do not get the wanted result as i am unable to control the position, caption keeps aligning to the bottom line of the figure?. FYI the result is the same for a text block...

I would like the output to have the exact look as here:

At least placement should be decided based on even and odd pages, and not pass through margins. I have tried a solution posted here on TeX.SE. It works, but not with out issues for instance larger space between text block and sidepar most importantly caption does not adhere to the top of the figure - any suggestion as to how this look could be obtained would be appreciated.

\documentclass[10pt,showtrims,a4paper,twoside]{memoir}

\usepackage[T1]{fontenc}
\usepackage{graphicx}
\usepackage{rotating}
\usepackage{fontspec}
\usepackage{microtype}
\usepackage{lipsum}
\usepackage[export]{adjustbox}

\sideparmargin{outer}
\settrimmedsize{24cm}{17cm}{*}
\setlrmarginsandblock{32.125mm}{*}{0.9}
\setulmarginsandblock{32.125mm}{*}{*}
\setmarginnotes{0.2\foremargin}{0.7\foremargin}{\onelineskip}

\setheadfoot{\onelineskip}{2\onelineskip}
\setheaderspaces{*}{2\onelineskip}{*}
\setlength{\trimtop}{0pt}

\setlength{\trimedge}{\stockwidth}
\addtolength{\trimedge}{-\paperwidth}

\checkandfixthelayout

\begin{document}
\lipsum[1-4]

\lipsum[1-4]
\sidepar {This is text in the sidecaption it is sould follow the margin set on even and odd pages}

%remove comment and add a figure (tex.pdf) to  your directory
%\begin{figure}[t]
%\sidepar {This is text in the sidecaption it is sould follow the margin set on even and odd pages}
%\includegraphics[width=\textwidth]{tex.pdf}
%\label{fig:tex}
%\end{figure}

\end{document}


Result of MVC:

UPDATE - Result with suggestion from @egreg it´s not quite perfect.. - is there an alternative method that would eliminate the need for adjustments?

## 2 Answers

If you simply need side captions with memoir, you can use the sidecaption environment.

MWE:

\documentclass[10pt,showtrims,a4paper,twoside]{memoir}

\usepackage[T1]{fontenc}
\usepackage{graphicx}
\usepackage{rotating}
\usepackage{fontspec}
\usepackage{microtype}
\usepackage{lipsum}
\usepackage[export]{adjustbox}

\setsidecappos{t}
\setlength\sidecapwidth{80pt}
\sidecapmargin{outer}

\begin{document}
\lipsum[1-3]

\begin{figure}[t]
\begin{sidecaption}{This is text in the sidecaption it is sould follow the margin set on even and odd pages}[fig:tex1]
\includegraphics[width=\textwidth,height=.9\textheight]{example-image-a}
\end{sidecaption}
\end{figure}

\begin{figure}[t]
\begin{sidecaption}{This is text in the sidecaption it is sould follow the margin set on even and odd pages}[fig:tex2]
\includegraphics[width=\textwidth,height=.9\textheight]{example-image-b}
\end{sidecaption}
\end{figure}

\end{document}


If you want the side caption to adhere to the picture, set

\setlength\sidecapsep{0pt}


and you will get

• Can sidecaption be used beside a text block ? – Strangelove Jan 3 '15 at 18:03
• @Strangelove Of course not. You can use sidelegend but I don't know how to make it recognize odd and even pages... – karlkoeller Jan 3 '15 at 18:19
• @Strangelove Otherwise, for text blocks, use \marginpar and set \marginparsep=\sidecapsep and \marginparwidth=\sidecapwidth – karlkoeller Jan 3 '15 at 18:52

\sidepar will always take into consideration the depth of the line which it's linked to. Try

\begin{tabular}[t]{c}x\\x\\x\\x\\z\end{tabular}%
\sidepar{This will be at the same height as z}


A workaround is to typeset the picture in another line and raise it, hiding the same amoung of raising.

\begin{figure}[tp]

\sidepar {This is text in the sidecaption it is sould follow the margin set on even
and odd pages}

\includegraphics[
width=\textwidth,
valign=t,
raise=\baselineskip,
set height=\dimexpr\height-\baselineskip,
]{example-image.pdf}%

\end{figure}


With valign=t (provided by adjustbox) we make the box extend only by a normal line's height above the baseline; with raise we shift it up for compensating the paragraph break, with set height we shave off the amount of raising.

A possible simplification is to use a custom command:

\newcommand{\sideincludegraphics}[3][]{%
\par\sidepar{#3}\par
\includegraphics[
#1,
valign=t,
raise=\baselineskip,
set height=\dimexpr\height-\baselineskip,
]{#2}\par
}


so the code would become

\begin{figure}[tp]

\sideincludegraphics[width=\textwidth]{example-image.pdf}
{This is text in the sidecaption it is sould follow
the margin set on even
and odd pages}

\end{figure}

• Beautiful, could this be placed in a \newcommand for simplicity? - or is there alternative method with would achieve the same side caption? – Strangelove Jan 3 '15 at 16:07
• @Strangelove Here it is. – egreg Jan 3 '15 at 16:17
• do you think sidecaption could be used? - aligning to the top is easy with \setsidecappos{t} but i am have difficulty controlling the margins, as the sidecaption does not seem to adhere to the margin – Strangelove Jan 3 '15 at 16:22
• @Strangelove I don't think it would work, because it goes in the text block, not in the margins. – egreg Jan 3 '15 at 16:24