将 include_graphics 的高度设置为节点的高度?

将 include_graphics 的高度设置为节点的高度?

考虑以下 tikz 代码:

\newcommand\Header{
\begin{tikzpicture}[remember picture, overlay]
\node[anchor=north, inner sep=0pt, outer sep=0pt] (header) 
at (current page.north) {\includegraphics[width=\paperwidth]{header.png}};

\node[anchor=north, inner sep=0pt, outer sep=0pt] (header_left) 
at (current page.north) {\includegraphics[height=
% SAME HEIGHT AS THE HEADER NODE ?
]{header_left.png}};

\draw [fill=nicedarkblue, draw=none] (header.south west) 
rectangle ($(header.south east)-(0,0.1cm)$);
\end{tikzpicture}
}

如何将第二张图像的高度设置为等于第一张图像的高度?

答案1

可能有更好的方法,但您可以使用let语法来计算标题的高度。

\documentclass{article}
\usepackage{graphicx}
\usepackage{tikz}
\usetikzlibrary{calc}
\newcommand\Header{%
\begin{tikzpicture}[remember picture, overlay]
\node [below, inner sep=0pt, outer sep=0pt] (header) 
at (current page.north) {\includegraphics[width=\paperwidth,height=2cm]{example-image.png}};

\path
  let
    \p1=(header.south),
    \p2=(header.north),
    \n1={\y2-\y1)}
  in
 node[anchor=north,inner sep=0pt, outer sep=0pt]
  at (\p2)
  {\includegraphics[height=\n1]{example-image-a}};
\end{tikzpicture}%
}
\begin{document}
\Header

Some text.
\end{document}

在此处输入图片描述

相关内容