3

I'm trying to draw a diagram with pictures with TikZ. I know that people can direct use \includegraphics within a node so that the picture will be placed there. My question is, how do I generate a rectangle-shaped node and place 2 (or more) picture in it, pictures should be placed from top to bottom instead of from left to right (what I get when simply use 2 \includegraphics).

Here is an example, consider the top picture called top_pic.png, and bottom called botton_pic.png (another question: how do I place the transform symbol like in picture?)

enter image description here

0

4 Answers 4

5

In general: If you want line breaks in a node, look at Manual/automatic line breaks and text alignment in TikZ nodes. See Stefan's answer for an example.

But that isn't necessarily convenient here, unless you have the transform symbol as an image or symbol in a font already. Probably better to use separate nodes, Another option, with separate nodes, is to use a \matrix as in the following example. The symbol can be drawn using arrow tips from the arrows.meta library.

enter image description here

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{arrows.meta}
\begin{document}
\begin{tikzpicture}
\matrix [draw] {
  \node {\includegraphics[width=5cm]{example-image-a}}; \\
  \draw [Circle-{Circle[open]}, thick] (0,0) -- (0,0.75); \\
  \node {\includegraphics[width=5cm]{example-image-b}}; \\
};
\end{tikzpicture}
\end{document}
4
  • thx a lot for the solution, it works fine. another question (maybe a little stupid), how can i adjust the size of matrix?
    – tyker1
    Apr 12, 2018 at 15:34
  • @user152531 The size is determined mainly by its contents, i.e. the images and the symbol in the middle, can you be more specific? If you want to modify the "padding" between the images and the frame, change the inner sep value, e.g. \matrix [draw,inner sep=3mm] { .... If you want to change the distance between the images and the symbol, modify the row sep, e.g. \matrix [draw,inner sep=3mm,row sep=3mm] {.... Apr 12, 2018 at 16:16
  • i mean to scale the whole matrix at once, cause the pictures are too large, even i can adjust them one by one, but maybe theres a way to adjust the size (like scalebox) of matrix?
    – tyker1
    Apr 13, 2018 at 18:29
  • @user152531 I don't really understand why you can't just use \includegraphics[width=5cm]{filename} as in my example. You can set the width of both images to the same length by adding \setkeys{Gin}{width=5cm} between \begin{tikzpicture} and \matrix, and using just \includegraphics{filename}. That said, you can of course just put the whole tikzpicture in a \scalebox or \resizebox, but you'll probably have to change the length and line width of the \draw that makes the symbol in the middle so that it fits, so I would change the size of the images. Apr 13, 2018 at 18:35
5

You could fit the graphics.

enter image description here

\documentclass[tikz,border=3.14pt]{standalone}
\usetikzlibrary{fit,positioning}
\begin{document}
\begin{tikzpicture}
\node (imgA){\includegraphics[width=6cm]{example-image-a}};
\node[below=1.5cm of imgA] (imgB){\includegraphics[width=6cm]{example-image-b}};
\node[circle,draw,thick,minimum width=2mm,below=1mm of imgA]  (circleA) {};
\node[circle,draw,fill,minimum width=2mm,above=1mm of imgB]  (circleB) {};
\draw (circleA) -- (circleB);
\node[draw,thick,fit=(imgA) (imgB)]{};
\end{tikzpicture}
\end{document}
4

You can put the pictures in a table inside a node. Then use a symbol for the transform symbol, e.g. from trfsigns.sty. (The \raisebox in the last row is to remove the extra depth added on the last row. I use the depth of \box11, which is the \strutbox, to get the depth).

\documentclass{article}
\usepackage{tikz}
\usepackage{graphicx}
\usepackage{trfsigns}
\begin{document}
\begin{tikzpicture}
  \node[draw]{%
    \begin{tabular}[b]{@{}c@{}}
      \includegraphics[width=0.5\linewidth]{example-image-a}\\
      \rotatebox{90}{$\Laplace$}\\
      \raisebox{-\dp11}{\includegraphics[width=0.5\linewidth]{example-image-b}}
    \end{tabular}%
  };
\end{tikzpicture}
\end{document}

enter image description here

2

You could also use multipart nodes, see PGF manual Section 67.6 p723.

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{shapes.multipart}
\begin{document}
\begin{tikzpicture}
  \node[rectangle split, draw, rectangle split parts = 3]{
  \includegraphics[width=5cm]{example-image-a}
  \nodepart{two}
  \includegraphics[width=5cm]{example-image-b}
  \nodepart{three}
  \includegraphics[width=5cm]{example-image-c}
        };
\end{tikzpicture}
\end{document}

enter image description here

You must log in to answer this question.

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