2

I'm sure this is answered somewhere. I've looked, but still having trouble getting exactly what I'm trying to do. Perhaps I need to use something I'm not familiar with. I'm trying to shift one of two graphics within a figure vertically, without changing the bounds of the entire figure itself.

Here is my default code and close to desired result:

\begin{figure}
\begin{center}
\hspace{-0.25in}\includegraphics[width=0.4\textwidth]{img/a.png}~
\hspace{-0.75in}\frame{\includegraphics[width=0.175\textwidth]{img/b.jpg}}
\end{center}
\caption[stuff]{\label{fig:stuff}Some stuff.}
\end{figure}

enter image description here

I am trying to shift the right graphic up vertically a little bit:
enter image description here

If I adjust with vspace positively/negatively like so, it increases/decreases space between the whole figure and the caption, instead of moving just the right graphic:

\begin{figure}
\begin{center}
\hspace{-0.25in}\includegraphics[width=0.4\textwidth]{img/a.png}~
\hspace{-0.75in}\vspace{0.25in}\frame{\includegraphics[width=0.175\textwidth]{img/b.jpg}}
\end{center}
\caption[stuff]{\label{fig:stuff}Some stuff.}
\end{figure}

enter image description here

How can I shift the right graphics up within the bounds of the figure without changing the space between the entire figure and the caption?

1
  • 1
    For future readers, I went down this rabbit hole because my background image had too much surrounding white space in it. Having removed that, any adjusting was no longer necessary.
    – delrocco
    Jul 19, 2019 at 18:26

1 Answer 1

3

You can achieve the following using the overpic package:

enter image description here

\documentclass{article}
\usepackage{graphicx}
\usepackage{overpic}
\begin{document}

\begin{figure}
  \centering   
  \begin{overpic}[width=0.4\textwidth]{example-image-a}
     \put(65,10){\includegraphics[width=0.175\textwidth]{example-image-b}}  
  \end{overpic}
\caption[stuff]{\label{fig:stuff}Some stuff.}
\end{figure}

\end{document}

The horizontal and vertical position of the smalle image can be changed by adjusting the values of x and y in \put(x,y).

4
  • This is great, but now the first graphic has been centered. I had it hspace'd negatively so it looks left aligned. Can I insert a negative hspace somewhere to do that? Or equivalent option for the overpic?
    – delrocco
    Jul 19, 2019 at 18:03
  • @delrocco: To left-align the image, simply remove the \centering command. If this does not result in the output you want to achive, please clarify.
    – leandriis
    Jul 19, 2019 at 18:19
  • That doesn't put it on the left for some reason. However, including package adjustbox and adding the option left did work. Thank you for your help!
    – delrocco
    Jul 19, 2019 at 18:24
  • @leandriis +1 for your code. Is it important, for your opinion, to edit your answer with adjustbox and left as the comment of delrocco?
    – Sebastiano
    Jul 20, 2019 at 12:02

You must log in to answer this question.

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