1

If often find myself writing:

\documentclass{standalone}

\usepackage{tikz}
\usetikzlibrary{calc}

\begin{document}

\begin{tikzpicture}

    \node (refNode) {\includegraphics[width=5em]{example-image-a}};

    % Boring way to define intensive coordinates relatively to it:
    \def\x{.2}  % e.g: "somewhat left"
    \def\y{.54} % e.g.: "slightly more than midway up"
    \coordinate (x) at ($(refNode.west)!\x!(refNode.east)$);   % boilerplate
    \coordinate (y) at ($(refNode.south)!\y!(refNode.north)$); % boilerplate
    \node[red] (intensively located) at (x |- y) {.};

\end{tikzpicture}

\end{document}

intense relative coordinates

Is there not a simpler way to get this? Something like

\node[relatively to aNode=(.2, .54), red] (cool) {.};

Also, the above boilerplate extends correctly to coordinates outside of [0,1], but it is not enough if refNode happens to be [rotate=34]: it needs to become even more complicated then.

I am surprised I find no tikz builtin utility to do this kind of relative positionning.. have I missed anything?

4

You install basically a local coordinate system on the reference node.

\documentclass{standalone}

\usepackage{tikz}
\usetikzlibrary{calc}

\begin{document}

\begin{tikzpicture}

    \node (refNode) {\includegraphics[width=5em]{example-image-a}};

    \begin{scope}[shift={(refNode.south west)},x={(refNode.south
    east)-(refNode.south west)},y={(refNode.north west)-(refNode.south west)}]
     \node[red] at (0.2,0.54) {.};
    \end{scope}

\end{tikzpicture}

\end{document}

enter image description here

And you can cast this in a style:

\documentclass{standalone}

\usepackage{tikz}
\usetikzlibrary{calc}

\begin{document}

\begin{tikzpicture}[local cs/.style={shift={(#1.south west)},x={(#1.south
    east)-(#1.south west)},y={(#1.north west)-(#1.south west)}}]

    \node (refNode) {\includegraphics[width=5em]{example-image-a}};

    \path[local cs=refNode] (0.2,0.54) node[red] {.};

\end{tikzpicture}

\end{document}
  • That is.. awesome! I'll \tikzset this in all my preambles from now on. Thank you :) – iago-lito May 23 at 12:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.