TikZ:相对于彼此居中节点和路径

TikZ:相对于彼此居中节点和路径

我正在尝试在图像上绘制一个文本框,如下所示:

在此处输入图片描述

以下是我目前所掌握的信息:

\documentclass{article}
\usepackage[paperwidth=50cm,paperheight=70cm,margin=1.3cm]{geometry}
\usepackage{xcolor}
\usepackage{tikz}

\definecolor{background}{HTML}{2C414C}
\definecolor{foreground}{HTML}{FFFFFF}

\begin{document}
\pagecolor{foreground}

\begin{center}
  \begin{tikzpicture}[y=0.80pt, x=0.80pt, yscale=-1, xscale=1, inner sep=0pt, outer sep=0pt]
    % IMAGE
    \node[anchor=north west,inner sep=0] at (0,0) {\includegraphics[scale=3.0]{example-image-c}};
    % OUTER RECTANGLE
    \path[draw=foreground,fill=background,line width=1.600pt]
      (232,465) rectangle (512,586);
    % INNER RECTANGLE
    \path[draw=foreground,fill=background,line width=0.800pt]
      (241,476) rectangle (502,576);
    % TITLE
    \path[fill=foreground] (340.3773,522.9204) node[above right] (text3826) {TITLE};
    % SUBTITLE
    \path[fill=foreground] (331.4183,546.7606) node[above right] (text3830) {SUBTITLE};
  \end{tikzpicture}
\end{center}

\end{document}

我如何能:

  1. 将外部矩形水平置于图像的中心。
  2. 将内矩形置于外矩形的中心。
  3. 将标题和副标题置于内矩形的中心,如图所示。

我不想(241,476)到处都使用精确的坐标。任何绘制此图的其他方法(即使没有 TikZ)都值得欢迎!

答案1

我会用图像命名节点,然后使用positioning和将其他东西放置在与该节点相关的位置fit。然后图片由三个节点组成:图片、带有文本的框和带有粗外线的框。

\documentclass[border=10pt]{standalone}
\usepackage{tikz}
\definecolor{background}{HTML}{2C414C}
\definecolor{foreground}{HTML}{FFFFFF}
\usetikzlibrary{positioning,fit}
\begin{document}
\begin{tikzpicture}[inner sep=0pt, outer sep=0pt, text=foreground, draw=foreground, fill=background, font=\sffamily\LARGE]
  \node (n) {\includegraphics{example-image}};
  \node (o) [draw, fill, double distance=2.5ex, double=background, line width=.8pt, inner ysep=20pt, inner xsep=50pt, anchor=south, above=5ex of n.south, align=center] {TITLE\\SUBTITLE};
  \node [draw, line width=1.6pt, fit=(o), inner sep=1.25ex] {};
\end{tikzpicture}
\end{document}

层中的节点

相关内容