在 tikz 图中对齐文本

在 tikz 图中对齐文本

我正在尝试将一些文字放在投影仪中的图形上方,例如

\begin{tikzpicture}
            \node[anchor=top ,inner sep=0] (image) at (0,0) {\includegraphics[width=60mm,height=110pt]{./chapter6/figures_susy/RankingMET08.eps}};
            \node[align=top west,black] at (image.center) {TEXT HERE};
        \end{tikzpicture}

但文本出现在图表的中间 - 我怎样才能使文本与图形的顶部对齐?

答案1

你犯了一些错误。anchor=top应该是anchor=northtop不存在。同样align=top west应该是align=left

代码:

\documentclass{beamer}
\usepackage{tikz}
\begin{document}
\begin{frame}
\begin{tikzpicture}
            \node[anchor=north,inner sep=0] (image) at (0,0) {\includegraphics[width=60mm,height=110pt]{example-image}};
            \node[align=left,black,anchor=south] at (image.north) {TEXT HERE};
        \end{tikzpicture}
\end{frame}
\end{document}

在此处输入图片描述

现在我们将两个图形放在同一行。我已将图形宽度改为 3 厘米,使它们变小,并增加了keepaspectratio防止它们扭曲的尺寸。调整图形宽度和4cm宽度right=4cm of image1以满足您的需求。

\documentclass{beamer}
\usepackage{tikz}
\usetikzlibrary{positioning}
\begin{document}
\begin{frame}
\begin{tikzpicture}
            \node[anchor=north,inner sep=0] (image1) at (0,0) {\includegraphics[width=30mm,height=110pt,keepaspectratio]{example-image}};
            \node[align=left,black,anchor=south] at (image1.north) {TEXT HERE};
            %% second figure Change 4cm appropriately.
            \node[anchor=north,inner sep=0,right=4cm of image1] (image2) {\includegraphics[width=30mm,height=110pt,keepaspectratio]{example-image-a}};
            \node[align=left,black,anchor=south] at (image2.north) {TEXT HERE};
        \end{tikzpicture}
\end{frame}
\end{document}

在此处输入图片描述

您还可以tikzpicture并排使用 2。

\documentclass{beamer}
\usepackage{tikz}
\begin{document}
\begin{frame}
\begin{tikzpicture}
            \node[anchor=north,inner sep=0] (image1) at (0,0) {\includegraphics[width=30mm,height=110pt,keepaspectratio]{example-image}};
            \node[align=left,black,anchor=south] at (image1.north) {TEXT HERE};
        \end{tikzpicture}%
%\hfill
\begin{tikzpicture}            
            \node[anchor=north,inner sep=0] (image2) at (0,0) {\includegraphics[width=40mm,height=110pt,keepaspectratio]{example-image-a}};
            \node[align=left,black,anchor=south] at (image2.north) {TEXT HERE};
        \end{tikzpicture}
\end{frame}
\end{document}

在此处输入图片描述

相关内容