2

I am using tikz to create an image that consists in three other images that I imported with includegraphics. Above each image, I want to add some text that should be centered with the image itself.

What is the correct way to do that?

enter image description here

\documentclass[12pt]{article}

\usepackage{graphicx} 
\usepackage{tikz}   

\begin{document}

\begin{figure*}[!t]

\centering
\begin{tikzpicture}

\node[anchor=south west,inner sep=0] at (0,0) {\includegraphics[width=0.35\columnwidth]{download}};
\node[draw, align=center] at (0,3) {some text};

\node[anchor=south west,inner sep=0] at (-5,0) {\includegraphics[width=0.35\columnwidth]{download}};

\node[anchor=south west,inner sep=0] at (5,0) {\includegraphics[width=0.35\columnwidth]{download}};

\end{tikzpicture}
\end{figure*}

\end{document}
1
  • Do you need TikZ for that? With a tabular{ccc} this can be achieved very easily. And even if TikZ is needed for whatever, a \matrix makes all the aligning just as easy as a tabular, including &s and \\s. Dec 19, 2022 at 16:09

4 Answers 4

4

Do you need TiKZ for it? I think a simple tabular can do it.

\documentclass[12pt]{article}

\usepackage{graphicx} 
%\usepackage{tikz}   

\begin{document}

\begin{figure*}[!t]

\centering
\begin{tabular}{ccc}
\fbox{Some Text} & \fbox{Some other text} & \fbox{Another text}\\[2mm]
\includegraphics[width=0.35\columnwidth]{example-image-a} &
\includegraphics[width=0.35\columnwidth]{example-image-b} &
\includegraphics[width=0.35\columnwidth]{example-image-c} \\
\end{tabular}
\end{figure*}

\end{document}

enter image description here

3

You could use the positioning library:

\documentclass[12pt]{article}

\usepackage{graphicx} 
\usepackage{tikz}   

\usetikzlibrary{positioning}

\begin{document}

\begin{figure*}[!t]

\centering
\begin{tikzpicture}

\node[anchor=south west,inner sep=0] (imagea) at (0,0) {\includegraphics[width=0.35\columnwidth]{example-image}};
\node[draw, align=center,above=0.5cm of imagea] {some text};

\node[anchor=south west,inner sep=0] at (-5,0) {\includegraphics[width=0.35\columnwidth]{example-image}};

\node[anchor=south west,inner sep=0] at (5,0) {\includegraphics[width=0.35\columnwidth]{example-image}};

\end{tikzpicture}
\end{figure*}

\end{document}

enter image description here

2
\documentclass[tikz, border=1cm]{standalone}
\begin{document}
\begin{tikzpicture}
\node[align=center] at (-5,0) {some text\\\includegraphics[width=0.35\columnwidth]{example-image-a}};
\node[align=center] at (0,0)  {some text\\\includegraphics[width=0.35\columnwidth]{example-image-b}};
\node[align=center] at (5,0)  {some text\\\includegraphics[width=0.35\columnwidth]{example-image-c}};
\end{tikzpicture}
\end{document}

Three images with text above

1

If you use positioning tikz library, you don't need to worry about coordinates and use relative placements with global settings to control space between nodes.

If you want text above a node, you could either add an extra label or another node with a text box (commented in the code below).

enter image description here

\documentclass[12pt]{article}
\usepackage{graphicx} 
\usepackage{tikz} \usetikzlibrary{positioning}

\begin{document}
\begin{figure*}
  \setkeys{Gin}{width=0.3\textwidth, height=2.5cm}
  \centering
  \begin{tikzpicture}[
      node distance = 3mm and 1mm,   % vert. and horiz. distance
      caption/.style = {draw, align=center},
    ]
    \node (A) [label={[caption]XxxxX}] {\includegraphics{example-image}};
    \node (B) [label={[caption]XxxxX},right=of A] {\includegraphics{example-image}};
    \node (C) [label={[caption]XxxxX},right=of B] {\includegraphics{example-image}};
    %\node [caption,above=of A] {Xxxx};
  \end{tikzpicture}
\end{figure*}
\end{document}

You must log in to answer this question.

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