3

I work on a Latex book template, and at the moment, I try to include a wide image on the top of a page, and another one on its bottom. The images should ignore the margin, and text should not overlap the images.

My first try result in something like this:

enter image description here

Code: \documentclass[10pt,a4paper,twocolumn,openany]{book}

\usepackage[english]{babel}
\usepackage{tikz}
\usepackage{graphicx}
\usepackage{lipsum}

\newcommand*{\rpgarttop}[1]{%
    \begin{figure*}[!t]%
    \begin{tikzpicture}[remember picture,overlay]
        \node[inner sep=0pt, anchor=north] at (current page.north) {\includegraphics[width=\paperwidth]{#1}};
    \end{tikzpicture}
    %%%%%%%%%%%%%%%%%%
    % need to get the image dimension here
    %\rule{image width}{image height}
    %%%%%%%%%%%%%%%%%%
  \end{figure*}%
}

\newcommand*{\rpgartbottom}[1]{%
    \begin{figure*}[!t]%
    \begin{tikzpicture}[remember picture,overlay]
        \node[inner sep=0pt, anchor=south] at (current page.south) {\includegraphics[width=\paperwidth]{#1}};
    \end{tikzpicture}
  \end{figure*}%

}


\begin{document}

\rpgarttop{art-top}
\rpgartbottom{art-bottom}
\section{Section 1}
\lipsum[1-15]


\end{document}

As you can see, the margin are ignored, but the text overlap the images.

If one of you have any idea to solve this issue, it will be super nice !

Also, here is a link to the entire project : https://github.com/Krozark/RPG-LaTeX-Template


Edit 1 : Add comment for image dimension

  • Welcome! You haven't left any room for them. overlay means it takes no space. So the text just starts where it normally would and ends where it normally would. You need to adjust your top margin and height of the text block. (Using geometry would be the easiest way. Then you can just set the top and bottom margins as you need.) – cfr Jun 28 '18 at 1:26
  • Thanks @cfr! But is there a way to get the image dimention from latex ? This way, I could calculate the margin that I have to add, as not all the page will have a top and/or bottom image, and those images will also change from pages to pages. – Krozark Jun 28 '18 at 7:52
  • 1
    Yes. Sometimes you can get the information directly. Depends a bit on engine, file type etc. Failing that, you can put it into a box and measure the box before typesetting it. This is probably the most flexible way, since it doesn't matter what is in the box. – cfr Jun 28 '18 at 21:21
1

I finally found a way to have the correct behavior: enter image description here

\documentclass[10pt,a4paper,twocolumn,openany]{book}

\usepackage{graphicx}
\usepackage{dblfloatfix}
\usepackage[strict]{changepage}

\usepackage{lipsum}

\newlength{\rpghmargin}
\newcommand*{\pagepicture}[2]{%
    \checkoddpage
    \ifoddpage
        \setlength{\rpghmargin}{\dimexpr 1in+\hoffset+\oddsidemargin+32pt \relax}
    \else
        \setlength{\rpghmargin}{\dimexpr 1in+\hoffset+\evensidemargin-25pt \relax}

    \fi
    \begin{figure*}[#1!]
        \centering
        \if #1t
            \vspace*{-\dimexpr1in+\voffset+\topmargin+\headheight+\headsep \relax}
        \fi

         \makebox[\paperwidth][l]{
            \hskip-\rpghmargin \relax
            \includegraphics[width=\paperwidth]{#2}
        }
        \if #1b
            \vspace*{-\dimexpr\paperheight-\textheight-1in+12pt-\voffset-\topmargin-\headheight-\headsep\relax}
        \fi

    \end{figure*}
}


\begin{document}

\pagepicture{t}{art-top}
\pagepicture{b}{art-bottom}

\lipsum 
\lipsum 

\end{document}

The links that help me :

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.