1

My document contains some info graphics in the margin. I realise it by the marginnote package. How do I align the top of an image to the top of the paragraph (\baseline+\height) with different factors in \setstretch?

Here is a MWE:

\documentclass{scrartcl}

% load packages
\usepackage{blindtext, setspace}
\usepackage{marginnote}
\usepackage{showframe}

\renewcommand*{\marginfont}{\tiny}

\begin{document}
\raggedleft

\blindtext

\marginnote{\rule{5mm}{20mm}}
X

\blindtext

\clearpage
\setstretch{1.6}

\blindtext

\marginnote{\rule{5mm}{20mm}}
X

\blindtext

\end{document}

The interesting parts are the top alignment of X to the top of \rule.

A small difference with no setstretch:

No <code>setstretch</code>

And a bigger difference with \setstretch{1.6}:

<code>\setstretch{1.6}</code>

My aim is, to align the top of the X with the top of the image by a length variable, to be independent from different line spaces.

Edit: Unfortunately, I forget one command in my MWE. I add the line \renewcommand*{\marginfont}{\tiny} because I would like to have a solution which is independent of the size of the chosen fontsize in marginnote. I tried to get the correct length in raise= but I failed. Is this possible?

1

It is hard to explain the entire story as it is late night, but here is an option using adjustbox macros. We define the macro:

\newcommand{\marginfig}[2][scale=0.1]{%
    \includegraphics[#1,valign=T,raise=\fontcharht\font`X]{#2}
    }

and use it like:

\documentclass{scrartcl}

% load packages
\usepackage{blindtext, setspace}
\usepackage[export]{adjustbox}
\usepackage[fulladjust]{marginnote}
\usepackage{showframe}

\newcommand{\marginfig}[2][scale=0.1]{%
    \includegraphics[#1,valign=T,raise=\fontcharht\font`X]{#2}
    }

\begin{document}
\raggedleft

\blindtext

\marginnote{\marginfig[width=1cm]{example-image-a}}
X

\blindtext

\clearpage
\setstretch{1.8}

\blindtext

\marginnote{\marginfig{example-image}}
X

\blindtext

\end{document}

Here we level the top of the image with the baseline of X and then raise it by the height of X.

enter image description here

enter image description here

5
  • Thanks! That look good! Unfortunately, I changed the size of the font in marginnote by \renewcommand*{\marginfont}{\tiny}. In this case, the box is not raised enough. Do you have an idea for this case? I extend my question with this command. – Dirk Sep 19 '15 at 9:29
  • Because you are raising the box by \fontcharht\font`\X in the \tiny size. If you put in the preamble \newlength\marginraise \begingroup\normalfont\normalsize\selectfont \global\setlength\marginraise{\fontcharht\font`\X} \endgroup and then change the macro to raise=\marginraise, I think it should work. – Manuel Sep 19 '15 at 9:42
  • I tried something similar. Unfortunately, the font selection of \normalfont does not work. Both images are not aligned properly. Do you know why? I think, raise= does not react on the variable. I assigned a fixed value to \marginraise and nothing happens. – Dirk Sep 19 '15 at 12:10
  • After trying around some time, I switched the order and put the marginnote inside the adjustbox. Then everything works fine: \newcommand*{\mymarginpic}[1]{\adjustbox{valign=T, raise=\fontcharht\font'X}{\marginnote{\includegraphics[width=\marginparwidth]{#1}}}} – Dirk Sep 19 '15 at 13:17
  • I'm not sure, does the swap make sense? – Dirk Sep 20 '15 at 8:25

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.