在tikz环境中对齐图片和文字

在tikz环境中对齐图片和文字

我正在使用tikz创建一个由我用 导入的另外三幅图像组成的图像includegraphics。我想在每幅图像上方添加一些文本,这些文本应与图像本身居中。

正确的做法是什么?

在此处输入图片描述

\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

你需要吗TiKZ?我认为简单的tabular就可以了。

\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}

在此处输入图片描述

答案2

您可以使用该positioning库:

\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}

在此处输入图片描述

答案3

\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}

上面有三张带文字的图片

答案4

如果您使用positioningtikz 库,则无需担心坐标,并使用具有全局设置的相对位置来控制节点之间的空间。

如果您希望文本位于节点上方,您可以添加一个额外的节点label或另一个带有文本框的节点(在下面的代码中注释)。

在此处输入图片描述

\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}

相关内容