2

I'm using XeLaTeX to draw a sticker header with TikZ, using two images and some text. I want to define the height of those images based on the height of the text node, which is defined according to the lines of text. For instance, if the height of the text node is 2cm, the height of both images should be 2cm.

I tried to use let to extract the y-coordinate based on this calculation:

\path let \p1 = ($(text.north west) - (text.south west)$) in node ...

But it didn't work (I'm not sure if that's a valid approach, or if I used the syntax incorrectly).

So, what should I do to achieve what I'm trying to do?

Here's a MWE of what I'm trying to do (it doesn't have the above instruction):

\documentclass{article}

\usepackage{geometry}
\geometry{paperwidth=10cm,paperheight=1.5cm}

\usepackage[dvipsnames]{xcolor}
\usepackage{graphicx}

\usepackage{tikz}
\usetikzlibrary{calc}

\pagestyle{empty}

\begin{document}
  \begin{tikzpicture}[remember picture, overlay]
    \node[anchor=north, font=\bfseries, align=flush center] (text) at ($(current page.north) + (0,-0.25)$) {This is the first line\\This is the second one};
    \node[anchor=east, inner sep=0pt] (image) at ($(text.west) + (-1.25,0)$) {\includegraphics[height=1cm]{example-image}};
    \node[anchor=west, inner sep=0pt] (image) at ($(text.east) + (1.25,0)$) {\includegraphics[height=1cm]{example-image}};
  \end{tikzpicture}
\end{document}

The output of the given file is this:

Output of the attached code

Any help will be appreciated!

1 Answer 1

2

Try this

\usepackage{graphicx}
\usepackage{tikz}
\usetikzlibrary{calc}

\begin{document}
\pagestyle{empty}
    \begin{tikzpicture}[remember picture, overlay]
\node[font=\bfseries, align=flush center, anchor=north] (text) at ($(current page.north) + (0,-0.25)$) 
    {This is the first line\\This is the second one};
\path   let \p1 = ($(text.north)-(text.south)$),
            \n1 = {veclen(\y1,\x1)} in
        node[anchor=east, inner sep=0pt] (image) at ($(text.west) + (-1.25,0)$)
            {\includegraphics[height=\n1]{example-image}}
        node[anchor=west, inner sep=0pt] (image) at ($(text.east) + (1.25,0)$) 
            {\includegraphics[height=1cm]{example-image}};
    \end{tikzpicture}
\end{document}

Image will appear after second run.

enter image description here

4
  • It works! Thanks a lot! By the way, what are veclen and \n? I didn't found them in the manual (I'm sure they should be there).
    – user101590
    Commented Jul 30, 2016 at 4:04
  • Forget it. I finally found out: veclen is sqrt(x^2+y^2) and \n is a number register used in let =)
    – user101590
    Commented Jul 30, 2016 at 4:08
  • 1
    veclen: vector length. it is described in manual in many places: 4 Tutorial: Euclid, than 14.15 The Let Operation etc
    – Zarko
    Commented Jul 30, 2016 at 4:10
  • Yeah, I didn't realize that (well, it's kinda difficult to get through that big manual) >_<
    – user101590
    Commented Jul 30, 2016 at 4:15

You must log in to answer this question.