13

I have a figure (eps file included using \includegraphics) inside a postscript environment where I use PSTricks to add labels and extra lines.

I want to add another eps file smaller in the top right so it is on the top of the other figure. Can I use \includegraphics or something similar (possibly in PSTricks) to put a new eps file partially on top of the other one, in the same postscript environment?

I want the result to look a bit like this: Graph with a second graph overlayed in the corner.

rtzll
  • 5,531
Heather
  • 836
  • To add some background, I generally run my eps files through processing with psfrag / pstricks and anything else to produce a pdf file which can then be directly dropped into a document compiled with pdflatex (and not using any --shell-escape). – Heather Feb 12 '13 at 16:52

4 Answers4

7

enter image description here

\documentclass[pstricks,border=12pt]{standalone}
\usepackage{graphicx}
\def\Row{5}
\def\Column{5}
\def\FilenameMain{example-image-A}
\def\FilenameChild{example-image-B}
\def\ScaleMain{1}
\def\ScaleChild{0.25}


\newsavebox\IBoxMain
\newsavebox\IBoxChild
\savebox\IBoxMain{\includegraphics[scale=\ScaleMain]{\FilenameMain}}
\savebox\IBoxChild{\includegraphics[scale=\ScaleChild]{\FilenameChild}}

\psset
{
    xunit=\dimexpr\wd\IBoxMain/\Column,
    yunit=\dimexpr\ht\IBoxMain/\Row,
}


\begin{document}
\begin{pspicture}[showgrid=top](\Column,\Row)
    \rput[bl](0,0){\usebox\IBoxMain}
    \rput[tr](4.5,4.5){\usebox\IBoxChild}
\end{pspicture}
\end{document}

Edit:

You might need a grid to exactly specify the position of the child figure. Then the following edit should help. Of course you have to turn off the grid at the final stage by changing showgrid=top to showgrid=false.

enter image description here

\documentclass[pstricks,border=12pt]{standalone}

\usepackage{graphicx}
\def\Row{5}
\def\Column{5}
\def\FilenameMain{example-image-A}
\def\FilenameChild{example-image-B}
\def\ScaleMain{1}
\def\ScaleChild{0.25}


\newsavebox\IBoxMain
\newsavebox\IBoxChild
\savebox\IBoxMain{\includegraphics[scale=\ScaleMain]{\FilenameMain}}
\savebox\IBoxChild{\includegraphics[scale=\ScaleChild]{\FilenameChild}}

\psset
{
    xunit=\dimexpr\wd\IBoxMain/\Column,
    yunit=\dimexpr\ht\IBoxMain/\Row,
}

\addtopsstyle{gridstyle}
{
    griddots=0,
    gridcolor=red,
    subgridcolor=white,
    subgriddiv=10,
}

\begin{document}
\begin{pspicture}[showgrid=top](\Column,\Row)
    \rput[bl](0,0){\usebox\IBoxMain}
    \rput[tr](4.5,4.5){\usebox\IBoxChild}
\end{pspicture}
\end{document}

Edit 2:

Compile the code above with either latex->dvips->ps2pdf sequence or a single call xelatex to obtain a PDF output (namely overlaid.pdf).

Later, from your main TeX input file, you can then import the PDF output (overlaid.pdf) as follows.

% this is the main TeX input file
\documentclass{article}
\usepackage{graphicx}
\begin{document}
\begin{figure}
\centering
\includegraphics[<any options>]{overlaid}
\caption{Overlaid image in action}
\label{fig:overlaid}
\end{figure}
Your text goes here...
\end{document}

Compile this main TeX input file with pdflatex. Note that this workflow makes your project well organized and cleaner.

  • This answer is very helpful. I hadn't seen the standalone documentclass before. It also seems to be a very configurable version for what I want to do. Thanks. – Heather Feb 12 '13 at 16:51
6

You can use the picture environment; with the help of the picture and calc packages we can easily place both graphs, the important thing is that the inner one is typeset after the outer one. Notice that this does not depend on pstricks, so it is a more portable solution.

\documentclass{article}
\usepackage{graphicx,picture,calc}
\usepackage{lipsum}
\begin{document}

\lipsum[2]

\begin{figure}[htp]
\centering
%% Use two temporary storage bins
\sbox0{\includegraphics{Graph1}}
\sbox2{\includegraphics{Graph2}} % add the necessary scaling options

\begin{picture}(\wd0,\ht0)
\put(0,0){\usebox0}
%% Adjust the -0.7cm and -0.5cm shifts
\put(\wd0 - \wd2 - 0.7cm,\ht0 - \ht2 - 0.5cm){\usebox{2}}
\end{picture}
\caption{Two graphs}
\end{figure}

\lipsum[2]

\end{document}

enter image description here

egreg
  • 1,121,712
2
\documentclass{article}
\usepackage{pst-plot}
\usepackage{graphicx}
\SpecialCoor
\begin{document}

\begin{pspicture}(6,3)
\psaxes[axesstyle=frame, ticksize=0 5pt](6,3)
\rput[tr](!6 0.25 sub 3 0.25 sub){\fbox{\includegraphics[width=1cm]{tiger}}}
\end{pspicture}
\end{document}

enter image description here

  • Isn't this basically the same as Garbage Collector's answer (using \rput inside a pspicture)? – Jake Feb 12 '13 at 15:42
  • I don't understand how the coordinates work here. Also, I don't want to live-draw the large graph, I already have the eps file that I want to include. – Heather Feb 12 '13 at 16:49
  • 1
    @Dom: The PostScript notation in (!6 0.25 sub 3 0.25 sub) equals to (5.75,2.75). – kiss my armpit Feb 13 '13 at 04:04
  • Ok, I get it, the ! means do a calculation, and the sub means subtraction. Thanks. – Heather Feb 13 '13 at 11:39
  • 1
    @Dom ! means that the following code is pure PostScript. There are other possibilities, too –  Feb 13 '13 at 13:18
1

For completeness, I am including here my final result as a minimal working example.

It is based on Garbage Collector's answer but heavily simplified. There are many extra parts, which are very useful to know but this is a simpler initial step.

It uses the \rput command inside the postscript environment. This example can also be compiled directly with pdflatex (because it uses auto-pst-pdf).

\documentclass{article}

\usepackage{auto-pst-pdf}
\usepackage{graphicx}
\usepackage{psfrag}
\usepackage{pstricks}

\begin{document}

\pagestyle{empty}

\begin{postscript}
\includegraphics[width=324pt]{parent-filename}
\rput(-3.7,5.3){\includegraphics[width=180pt]{child-filename}}
\end{postscript}

\end{document}

This simply adds the child figure on top of the already positioned parent figure. The coordinates for rput are strange, because the initial \includegraphics is not inside an rput and somehow sets the 0,0 as bottom right.

Heather
  • 836