I would like to create "complex" picture which contains ellipse node.
To draw the "complex" picture, I need dimensions of that ellipse node before I draw it.
Unfortunately, since the node shape is ellipse, I can't calculate its dimensions by just measuring dimensions of the text in it.

Therefore, I would like to:

  1. Create fake tikz picture with just that ellipse node.
  2. Set global variables with correct dimensions of ellipse node while in fake picture environment.
  3. Drop the fake picture(Do not generate it anyhow, anywhere).
  4. Create "complex" picture by using the global variables with dimensions of ellipse node.

Also, it is highly preferable to be able to use calculations with fake tikz picture in preamble.

General idea(not compilable):

\documentclass {article}
\RequirePackage [utf8] {inputenc}
\RequirePackage {xparse}
\RequirePackage {tikz}

\usetikzlibrary {shapes}


    \dim_new:N \l_x_west
    \dim_new:N \l_x_east

    \dim_new:N \g_ellipse_width

    % Fake picture which will not be generated, just used for calculation of ellipse width.
    \begin {FAKE tikzpicture}

        \node (ellipse) [ellipse, fill = blue] { Some~text.};

        \pgfextractx {\l_x_west} {\pgfpointanchor {ellipse} {west}}
        \pgfextractx {\l_x_east} {\pgfpointanchor {ellipse} {east}}
        \dim_gset:Nn \g_ellipse_width {\l_x_east - \l_x_west}

    \end {FAKE tikzpicture}


\begin {document}

    \begin {tikzpicture}
        % Draw complex picture using the \g_ellipse_width
    \end {tikzpicture}

\end {document}

Is there any method to achieve this fake tikz picture environment?

  • 2
    Yes, you can use e.g. a \savebox to measure things. Note, however, that in most real life situations this is not necessary. – user121799 Jul 30 '19 at 0:27
  • 3
    \documentclass{article} \usepackage{tikz} \usetikzlibrary{shapes.geometric} \newsavebox\sandbox \begin{document} \savebox\sandbox{\tikz{\node[ellipse]{hello world};}} the ellipse is \the\wd\sandbox\space wide and \the\ht\sandbox\space high. \end{document} – user121799 Jul 30 '19 at 0:32
  • @marmot, as always, fast with all the answers that I need! Thank you, again :D Please make it official answer so I can accept it. – Iskustvo Jul 30 '19 at 0:49
  • As long as your problem is solved, from my perspective everything is fine. I am retiring from this site, in which rogue users can do as much harm as they want. – user121799 Jul 30 '19 at 1:44
  • It is, thank you! I am very sorry to hear that, I hope you change your mind... – Iskustvo Jul 30 '19 at 6:28

As marmot answered in the comment, here is the solution using the savebox to save picture's dimensions without drawing it.




            \node[ellipse]{hello world};

    the ellipse is \the\wd\sandbox\space wide and \the\ht\sandbox\space high.

For a case when \tikzexternalize is used, see this question.

| improve this answer | |

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.