4

I'm trying to create a chapter/section header with a side image, both flush with the page border, to be used multiple times throughout a document. The header images (A) are all the same dimensions, but the side images (B) vary in size but will be 9cm in width (they can be a short table, an average diagram or a tall image). I have tried regular wrapfig solutions with images, but the side images (B) keep floating around and I don't want to have to manually position every image (thus the node anchor).

Edit: To clarify, the reason the \section is placed above the images in the text is due to an automation that retrieves the chapter/section number and then uses the image with the same name.

Post completion edit: The accepted answer, including the comment, is relevant to solving this.

Actual result vs desired result

Text for actual result:

\documentclass[a4paper,10pt]{article}
\usepackage[T1]{fontenc}
\usepackage{lipsum}
\usepackage[margin=15pt]{geometry}
\usepackage{graphicx}
\usepackage{tikz}
\usepackage{wrapfig}

\begin{document}

\vspace*{11.50 cm} %to get the title under image (A) \section{Title} %Image A: \begin{tikzpicture}[remember picture,overlay,shift={(current page.north east)}] \node[anchor=north east,xshift=0.125cm,yshift=0.125cm]{\includegraphics[width=21cm,height=12.6cm]{example-image-a}}; \end{tikzpicture} %Image B: \begin{wrapfigure}{r}{0.43\textwidth} \begin{tikzpicture}[remember picture,overlay,shift={(current page.north east)}] \node[anchor=north east,xshift=0.13cm,yshift=-12.45cm]{\includegraphics[width=9cm,height=12.6cm]{example-image-b}}; \end{tikzpicture} \end{wrapfigure}

\lipsum[1-4]

\end{document}

Disclaimer: I am relatively new to LaTeX and thus can not be held accountable for my janky solutions.

2 Answers2

3

Like this:

enter image description here

\documentclass[a4paper,10pt]{article}
\usepackage[T1]{fontenc}
\usepackage{lipsum}
\usepackage[margin=15pt]{geometry}
\usepackage{graphicx}
\usepackage{tikz}
\usepackage{wrapfig}

\begin{document} %Image A: \begin{tikzpicture}[remember picture,overlay] \node[anchor=north west, inner sep=0pt] at (current page.north west) {\includegraphics[width=21cm,height=12.6cm]{example-image-a}}; \end{tikzpicture}

\vspace{12.6cm} \section{Title} %Image B: \begin{wrapfigure}{r}{0.43\textwidth} \vspace{-\baselineskip} \begin{tikzpicture} \node {\includegraphics[width=\linewidth,height=12.6cm]{example-image-b}}; \end{tikzpicture} \end{wrapfigure} \lipsum[1-4]

\end{document}

Zarko
  • 296,517
  • Thanks for the suggestion. While it does clean up some of the mess in my code it moves image B away from the page edge as well as away from image A.

    It did help me solve this though by setting \vspace{-2.46cm} and width=9cm, so thanks for the reply!

    – Oscar105 Dec 08 '20 at 16:02
1

This solution uses the flowfram package. Note that all (x,y) locations are given relative to the lower left corner of the text area, hence \ypage and \xright. Also, flowfram will not change the width of a paragraph which is split between two frames, so one must manually break the paragraphs using \nopar.

\documentclass[a4paper,10pt]{article}
\usepackage[T1]{fontenc}
\usepackage{lipsum}
\usepackage[margin=15pt]{geometry}
\usepackage{graphicx}

\newcommand{\nopar}{{\parfillskip=0pt\parskip=0pt\par}\noindent}

\newcommand{\ypage}{\the\dimexpr 1in+\topmargin+\headheight+\headsep+\textheight} \newcommand{\xrightodd}{\the\dimexpr \paperwidth-1in-\oddsidemargin}% see page specification \newcommand{\xrighteven}{\the\dimexpr \paperwidth-1in-\evensidemargin}

\usepackage{flowfram} \newstaticframe[1]{21cm}{12.6cm}{\dimexpr-1in-\oddsidemargin}% {\dimexpr \ypage-12.6cm}[tophead] \newstaticframe[1]{9cm}{12.6cm}{\dimexpr\xrightodd-9cm}% {\dimexpr \ypage-12.6cm-12.6cm}[sidehead] \newflowframe[1]{\dimexpr \xrightodd-9cm-\columnsep}{\dimexpr 12.6cm-\intextsep}% {0pt}{\dimexpr \ypage-12.6cm-12.6cm} \newflowframe[1]{\textwidth}{\dimexpr \ypage-12.6cm-12.6cm}% {0pt}{0pt} \begin{staticcontents}{tophead} \includegraphics[width=21cm,height=12.6cm]{example-image-a} \end{staticcontents} \begin{staticcontents}{sidehead} \includegraphics[width=9cm,height=12.6cm]{example-image-b} \end{staticcontents}

\begin{document} \section{Title}

\lipsum[1-2]

Nulla malesuada porttitor diam. Donec felis erat, congue non, vo- lutpat at, tincidunt tristique, libero. Vivamus viverra fermentum felis. Donec nonummy pellentesque ante. Phasellus adipiscing semper elit. Proin fermentum massa ac quam. Sed diam turpis, molestie vitae, plac- erat a, molestie nec, leo. Maecenas lacinia. Nam ipsum ligula, eleifend at, accumsan nec, suscipit a, ipsum. Morbi blandit ligula feugiat magna. Nunc eleifend consequat lorem. Sed lacinia nulla vitae enim. Pellentesque \nopar% manual paragraph break tincidunt purus vel magna. Integer non enim. Praesent euismod nunc eu purus. Donec bibendum quam in tellus. Nullam cursus pulvinar lectus. Donec et mi. Nam vulputate metus eu enim. Vestibulum pellentesque felis eu massa.

\lipsum[4]

\end{document}

John Kormylo
  • 79,712
  • 3
  • 50
  • 120