3

I would like to add an image in the margin beside the header. The bottom of the image should be align with the header baseline. In my MWE (see below) the top of the image is adjusted with the header top.

How can I adjust the image at the baseline?

Do you suggest other improvements? E.g. does it make sense to use marginnote in ihead?

MWE:

\documentclass{scrreprt}

\usepackage{blindtext, graphicx, marginnote}
\usepackage[twoside = true]{geometry}
\usepackage[automark, headsepline, footsepline, plainfootsepline]{scrlayer-scrpage}

\ihead{%
    \marginnote{%
            \includegraphics[width=\marginparwidth]{example-image-a}%
        }
}

\begin{document}
\Blinddocument
\end{document}
3

I would not use marginnote but only scrlayer-scrpage:

\documentclass{scrreprt}

\usepackage{mwe,graphicx}
\usepackage[twoside = true]{geometry}
\usepackage[automark, headsepline, footsepline, plainfootsepline]{scrlayer-scrpage}

\rohead{\headmark\makebox[0pt][l]{\hskip\marginparsep\includegraphics[width=\marginparwidth]{example-image-a}}}
\lehead{\makebox[0pt][r]{\includegraphics[width=\marginparwidth]{example-image-a}\hskip\marginparsep}\headmark}

\begin{document}
\Blinddocument
\end{document}

enter image description here

You could also add your own layer to the page style scrheadings and if you want the image also on plain pages to plain.scrheadings:

\documentclass{scrreprt}

\usepackage{mwe,graphicx}
\usepackage[twoside = true]{geometry}
\usepackage[automark, headsepline, footsepline, plainfootsepline]{scrlayer-scrpage}

\DeclareNewLayer[background,
  head,
  addhoffset=\ifodd\value{page}\textwidth+\marginparsep\else-\marginparwidth-\marginparsep\fi,
  width=\marginparwidth,% optional reduce layer width
  contents={\includegraphics[width=\marginparwidth]{example-image-a}}]{image}

\AddLayersToPageStyle{scrheadings}{image}
%\AddLayersToPageStyle{plain.scrheadings}{image}

\begin{document}
\Blinddocument
\end{document}

The result is the same, but you do not need to split of \ihead into \lehead and \rohead. And you just have to activate the single commented line to activate the image for plain pages.

BTW: I would suggest to put the image one time into a box and use the box on each page:

\documentclass{scrreprt}

\usepackage{mwe,graphicx}
\usepackage[twoside = true]{geometry}
\usepackage[automark, headsepline, footsepline, plainfootsepline]{scrlayer-scrpage}

\newsavebox\headimagebox
\AtBeginDocument{\sbox\headimagebox{\includegraphics[width=\marginparwidth]{example-image-a}}}
\DeclareNewLayer[background,
  head,
  addhoffset=\ifodd\value{page}\textwidth+\marginparsep\else-\wd\headimagebox-\marginparsep\fi,
  width=\marginparwidth,
  contents=\usebox\headimagebox]{image}

\AddLayersToPageStyle{scrheadings}{image}
\AddLayersToPageStyle{plain.scrheadings}{image}% used on chapter start page

\begin{document}
\Blinddocument
\end{document}

And if the code should place the logo always to the right side in single-side mode:

\documentclass{scrreprt}
%\documentclass[twoside]{scrreprt}

\usepackage{mwe,graphicx}
\usepackage{geometry}
\usepackage[automark, headsepline, footsepline, plainfootsepline]{scrlayer-scrpage}

\newsavebox\headimagebox
\AtBeginDocument{\sbox\headimagebox{\includegraphics[width=\marginparwidth]{example-image-a}}}
\makeatletter
\DeclareNewLayer[background,
  head,
  addhoffset=\ifcase\if@twoside \ifodd\value{page} 0 \else 1 \fi\else 0 \fi\textwidth+\marginparsep\else-\wd\headimagebox-\marginparsep\fi,
  width=\marginparwidth,
  contents=\usebox\headimagebox]{image}
\makeatother

\AddLayersToPageStyle{scrheadings}{image}
\AddLayersToPageStyle{plain.scrheadings}{image}% used on chapter start page

\begin{document}
\Blinddocument
\end{document}

But in this case it could be easier to use different layers for left and right pages:

\documentclass{scrreprt}
%\documentclass[twoside]{scrreprt}

\usepackage{mwe,graphicx}
\usepackage{geometry}
\usepackage[automark, headsepline, footsepline, plainfootsepline]{scrlayer-scrpage}

\newsavebox\headimagebox
\AtBeginDocument{\sbox\headimagebox{\includegraphics[width=\marginparwidth]{example-image-a}}}
\DeclareNewLayer[background,
  oddpage,% for right pages in double-side mode or all pages in single-side mode
  head,
  addhoffset=\textwidth+\marginparsep,
  width=\marginparwidth,
  contents=\usebox\headimagebox]{image.odd}
\DeclareNewLayer[background,
  evenpage,% for left pages in double-side mode
  head,
  addhoffset=-\wd\headimagebox-\marginparsep,
  width=\marginparwidth,
  contents=\usebox\headimagebox]{image.even}

\AddLayersToPageStyle{scrheadings}{image.odd,image.even}
\AddLayersToPageStyle{plain.scrheadings}{image.odd,image.even}% used on chapter start page

\begin{document}
\Blinddocument
\end{document}
  • Thanks, that works like a charm! Do you have a suggestion to optimise addhoffset for twoside=false? – Dirk Apr 27 '17 at 8:54
  • How big is the benefit to use a savebox? – Dirk Apr 27 '17 at 9:03
  • 1
    @Dirk With the savebox the \includegraphics code is expanded only once while the \sbox. Without it has to be expanded on every page. So if you have only one page there wouldn't be a benefit but if you have thousand pages … I like to do things once and use them often independent from any obvious benefit. – Schweinebacke May 2 '17 at 6:32

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.