1

I am trying to overlap an image with an arbitrary text in a variable-width minipage. I want a minipage because the minipage will be next to another minipage of a variable-width as well. And I have experimented with tikzpicture with overlay option.

\documentclass[11pt, oneside]{article} 
\usepackage{geometry}
\geometry{letterpaper}
\usepackage{graphicx}
\usepackage{tikz}
\usepackage{lipsum}  

\begin{document}

\begin{minipage}[c]{0.7\textwidth}
    \lipsum[1-1]
\end{minipage}\begin{minipage}{0.3\textwidth}
    \centering
    \begin{tikzpicture}[overlay]
        \node{\includegraphics[scale=0.2]{example-image-a}};
    \end{tikzpicture}\par
    Author
\end{minipage}

\vspace{5\baselineskip}

\begin{minipage}[c]{0.4\textwidth}
    blah blah blah
\end{minipage}\begin{minipage}{0.6\textwidth}
    \centering
    \begin{tikzpicture}[overlay]
        \node{\includegraphics[scale=0.5]{example-image-a}};
    \end{tikzpicture}\par
    Written by an author
\end{minipage}

\end{document}  

And this is what I get.

Result

I want the center of the image to be located at the center of the text. The image also needs to be inserted before the overlapping text because the image has a white background color which can hide the text if drawn later.

Would there be a trick to move the image over the text or configure a background image of a single minipage only?

1 Answer 1

2

Since the anchor of a TikZ node is its center by default, the easiest way is to enter the text to be overlayed onto the images as the contents of a node, as follows.

Two equivalent techniques:

  1. Placing the node at an explicit coordinate ((0,0) is where the overlayed picture is inserted in the LaTeX document):

    \node at (0,0) {\includegraphics[scale=0.2]{example-image-a}};
    \node at (0,0) {Author};
    
  2. Using the implicit (0,0) of the first coordinate, naming the first node and implicitly using its center anchor to position the second node:

    \node (image) {\includegraphics[scale=0.5]{example-image-a}};
    \node at (image) {Written by an author};
    

Full code:

\documentclass[11pt, oneside]{article}
\usepackage{geometry}
\geometry{letterpaper}
\usepackage{graphicx}
\usepackage{tikz}
\usepackage{lipsum}

\begin{document}

\begin{minipage}[c]{0.7\textwidth}
    \lipsum[1-1]
\end{minipage}\begin{minipage}{0.3\textwidth}
    \centering
    \begin{tikzpicture}[overlay]
\node at (0,0) {\includegraphics[scale=0.2]{example-image-a}};
\node at (0,0) {Author};
    \end{tikzpicture}\par
\end{minipage}

\vspace{5\baselineskip}

\begin{minipage}[c]{0.4\textwidth}
    blah blah blah
\end{minipage}\begin{minipage}{0.6\textwidth}
    \centering
    \begin{tikzpicture}[overlay]
        \node (image) {\includegraphics[scale=0.5]{example-image-a}};
        \node at (image) {Written by an author};
    \end{tikzpicture}\par
\end{minipage}

\end{document}

enter image description here

1
  • Thank you! This is exactly what I was looking for.
    – user207854
    Mar 17, 2020 at 9:05

You must log in to answer this question.

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