0

LaTeX noob here.

I am trying to position images (no fixed height) in the upper right corner of a page. To achieve this I am using tikz with the overlay and remember picture options as suggested elsewhere. However this obviously means that any text I want to include gets overlayed on top of the picture, while I would like the text to appear below as if it was a normal figure.

The following is a minimal working example


\RequirePackage{tikz}
\RequirePackage{geometry}

%Used to make calculations with coordinates for positioning
\RequirePackage{calc}

%Width of border on the left with section title
\newlength{\titleborderwidth}

%Set border width
\setlength{\titleborderwidth}{0.16\paperwidth}

%Set page geometry
\geometry{inner=\titleborderwidth}

\begin{document}
        \begin{tikzpicture}[remember picture, overlay]
            \node[anchor=north east] at (current page.north east){
                \includegraphics[width=\paperwidth-\titleborderwidth]{example-image-a}
            };
        \end{tikzpicture}
\\
I would like this text to appear below the picture


\end{document}

This produces:

Additionally:

  • The reason I need the border width is since the document I am planning has a border on which the title lies vertically on the left side.

  • Currently with this MWE the image does not appear to fit perfectly in the upper right corner, but appears to have some white margins and I am not sure why.

  • I was not able to figure out whether there is a way to obtain the size of the picture (which is not preset and may be changing) to use it as an argument for \vspace.

  • I would prefer to use tikz since in the final document I am using other tikz objects with the shadows library, and I would like to be able to use that same library for this image as well.

I spent already a lot of time trying to figure this out on my own, but did not come to any solution that is not hacky or tacky. I would be really glad if you could bestow some LaTeX knowledge on me. Thanks!

1
  • BTW, you can compute the left margin using {\dimexpr 1in+\oddsidemargin} or {\dimexpr 1in+\evensidemargin} for even pages with a two sided document class. The 1in is hard coded into the TeX engine. Commented Sep 6, 2021 at 16:09

2 Answers 2

0

It seems like you want to continue texting after the picture. So the picture is part of your text, not a floating object (in CSS sense). So the only thing unusual here is that the picture should touch the top margin. This is easy as long as you know exactly what's in that margin.

\documentclass{article}
\usepackage{geometry}
    \newlength{\titleborderwidth}
    \setlength{\titleborderwidth}{0.16\paperwidth}
    \geometry{inner=\titleborderwidth}
\usepackage{layout}
\usepackage{tikz}
\begin{document}
    \xdef\exacttopmargin{\the\dimexpr1em+\headsep+\headheight+\topmargin+1in\relax}%
    \vspace*{-\exacttopmargin}%
    \xdef\picturewidth{\the\dimexpr\paperwidth-\titleborderwidth\relax}%
    \noindent\includegraphics[width=\picturewidth]{example-image-a}
    
    I would like this text to appear below the picture.
    And you can.
    As you see, the only thing you need to do
    is to ``unskip'' the the correct amount of top margin
    so that the picture appears right on the top border.
    To obtain the correct amount of top margin,
    use package layout and use the command \texttt{\string\layout}.
    This command will draw the page layout and tell you the commands
    that represents the distances between certain layout-objects.
    Once you see the layout, you know what dimensions to add together.
    And then you add the negative of that dimensions.
    And you are done.
    You may also want to checkout the package showframe,
    which shows the layout on every page.
    
    \layout
\end{document}

the first page of a document, where an example picture touches the top margin

3
  • This works! I was also able to combine it with the tikz environment so that I can use the library I was interested in. Thanks for the good lesson as well, will definitely make use of it in the future! Commented Sep 6, 2021 at 9:18
  • You can still put that picture in tikz. (I mean, then tikz becomes the picture itself)
    – Symbol 1
    Commented Sep 6, 2021 at 17:10
  • PS. Try to add \lineskip to the sum if the top margin looks wrong.
    – Symbol 1
    Commented Sep 6, 2021 at 23:49
0
\documentclass{article}
\usepackage{graphicx}
\RequirePackage{tikz}
\RequirePackage{geometry}

%Used to make calculations with coordinates for positioning
\RequirePackage{calc}

%Width of border on the left with section title
\newlength{\titleborderwidth}

%Set border width
\setlength{\titleborderwidth}{0.16\paperwidth}

%Set page geometry
\geometry{inner=\titleborderwidth}

\begin{document}
        \begin{tikzpicture}[remember picture, overlay]
            \node[anchor=north east, align=left, inner sep=0] at (current page.north east){
                \includegraphics[width=\paperwidth-\titleborderwidth]{example-image-a} \\
                I would like this text to appear below the picture
            };
        \end{tikzpicture}
\end{document}

Sample image in top left corner

1
  • Left aligning and inner sep clear the issue with the border, so thanks for that! However putting the text in the node ties it to that tikzpicture environment, and if I want to write anything else on the page I would have to place it there, which does not really work for me. Commented Sep 6, 2021 at 9:00

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .