5

I have a picture which needs to be placed above another figure that I drew using tikzpicture. The pictures are being positioned side by side.

\documentclass{standalone} 

\usepackage{tikz} 

\begin{document} 
\includegraphics[scale=1]{m4.pdf}
\begin{tikzpicture} 

\node(A0) at (0,0) {p = 0};
\node(A1) at (10,0) {p = 1};

\path[->] (A0) edge node [below] {Increasing Ramdomness} (A1);

\end{tikzpicture}
\end{document}

The output is: enter image description here

I want it to be like:

enter image description here

AndréC
  • 24,137
  • Welcome to TeX.SE. You only need to put the picture in a node, \node at (5,3) {\includegraphics[scale=1]{m4.pdf}};. However, I do not have your picture, so I do not know if (5,3) works, you may need to use different coordinates. –  Nov 16 '18 at 05:01
  • @CarLaTeX I dunno, how would anyone benefit from this? It is, at least by some standards, a duplicate of this question. And this answer will always give you an idea which coordinates are to be used. (I would probably just draw these graphs with TikZ.) –  Nov 16 '18 at 05:49
  • @CarLaTeX Morally I agree but thanks to the tikz-pgf gold badge I can no longer just vote to close a question as a duplicate. –  Nov 16 '18 at 05:57
  • @marmot Close vote retracted since there's an answer – CarLaTeX Nov 16 '18 at 06:33

3 Answers3

2

Just load the optional preview package of the standalone class, and I quote (page 9):

If enabled this option loads the preview package with the tightpage option and wraps the content into a preview environment. This crops the content to its natural size plus a specified border.

exemple

\documentclass[preview]{standalone} 

\usepackage{tikz} 
\usepackage{mwe}
\begin{document} 
\includegraphics[scale=1]{example-image-a}
\begin{tikzpicture} 

\node(A0) at (0,0) {p = 0};
\node(A1) at (10,0) {p = 1};

\path[->] (A0) edge node [below] {Increasing Ramdomness} (A1);

\end{tikzpicture}
\end{document}
AndréC
  • 24,137
2

By default standalone processes the content in restricted horizontal mode which means like inside \hbox{..} or \mbox{..}. This means there can't be line breaks like in paragraphs. If you like to have line breaks / paragraphs you need to either provide the varwidth class option or the preview class option. The first uses a varwidth environment from the varwidth package around the content. The second switches the cropping code from standalones own code to the preview package, which also allows paragraphs.


In this specific case you could also just place the \includegraphics inside a TikZ \node to place it as part of the picture on top of the other material.

Martin Scharrer
  • 262,582
1

You can also do something like below.

\documentclass[tikz]{standalone} 
\usepackage{mwe}
\begin{document} 

\begin{tikzpicture} 
\node at (0,0) {\includegraphics[width=4cm]{example-image-a}};
\node at (4,0) {\includegraphics[width=4cm]{example-image-b}};
\node at (8,0) {\includegraphics[width=4cm]{example-image-a}};
\node(A0) at (0,-2) {p = 0};
\node(A1) at (8,-2) {p = 1};
\path[->] (A0) edge node [below] {Increasing Ramdomness} (A1);
\end{tikzpicture}
\end{document}

enter image description here

Display Name
  • 46,933