Express boxes properties in tikz coordinates

In my understanding, any LaTeX box displays such fundamental properties:

.. and anything is wrapped into a LaTeX box.

So, when I produce a tikz picture, it must be somehow wrapped into a box. Indeed, it seems to display such a height and a baseline when I use it. For instance, this code:

\documentclass{report}

\usepackage[english]{babel}

\usepackage{tikz}
\tikzset{x=1pt, y=1pt, z=1pt}

\begin{document}

\newcommand{\mypicture}{\begin{tikzpicture}
\node (a) at (0, 0) {\strut$a$};
\node (b) at (30, 0) {\strut$b$};
\draw[->] (a) .. controls (15, -20) and (30, -30) .. (b);
\end{tikzpicture}}

In my rather long, multilined text, I wish I could insert \mypicture{} just
as if it were something natural..

\end{document}


produces:

.. now I think my point is getting clear. The above insertion does not seem natural at all since \mypicture box baseline does not match node (a) baseline. And if it would, vertical space between the two lines would probably be affected.

How to correct this without a dirty hand-tweak with \raisebox, \vspace etc.?

How to express all tikz pictures box properties in tikz coordinates?

• You can use [baseline, every node/.style={anchor=base}] as options of your tikzpicture – moospit Feb 24 '16 at 10:59
• @moospit this is nice, thanks. What about the other box properties like height and width? (see updated question) – iago-lito Feb 24 '16 at 11:09
• @lago-lito from your question i read that your problem is the affection of the space between lines. I suggest the following ways to overcome this: 1) use another type of arrow or 2) use a overlay scope if the arrow may overlay other lines – moospit Feb 24 '16 at 11:19
• This certainly is the problem one might read from my example, and your suggestion is a workaround dedicated to this case. My actual problem is to choose by myself properties of the box produced by tikzpicture environment like height, width, baseline and depth and to express them in tikz coordinates. For instance, what if I needed to recreate this p with tikz (adding, say, one horn) and make it behave correctly within natural text? – iago-lito Feb 24 '16 at 11:26
• You could use the options xscale and yscale as options for your tikzpicture. As you set x, y, z to be 1pt this would be your base scaling. Doing it this way you could affect the scaling of all tikz-elements but not text. I don't believe that tikz is the best way to go when you want to create new characters (as your p) – moospit Feb 24 '16 at 11:40

In this case, you will have to tell TikZ where you want your baseline to be. Here you want it to be for example on your (a) node.

Here is a code to provide it :

\documentclass{report}

\usepackage[english]{babel}

\usepackage{tikz}
\tikzset{x=1pt, y=1pt, z=1pt}

\begin{document}

\newcommand{\mypicture}{\begin{tikzpicture}[baseline=(a.base)]
\node (a) at (0, 0) {\strut$a$};
\node (b) at (30, 0) {\strut$b$};
\draw[->] (a) .. controls (15, 20) and (30, 30) .. (b);
\end{tikzpicture}}

In my text, insert \mypicture{} just as if it were something natural..

\end{document}


And its result :

I hope it may help.

• This does help, thanks :) What about the other box properties like height and width? (see updated question) – iago-lito Feb 24 '16 at 11:08
• To obtain TikZ figure height and width, I think this post may be usefull tex.stackexchange.com/questions/137356/…. – Damien Dtx Feb 24 '16 at 11:14
• I am not sure how this would help. I need to somehow constrain properties of the figure box, what would I use their spontaneous height and width for? – iago-lito Feb 24 '16 at 11:19
• What do you mean by constraining the box? Autoscaling? – percusse Feb 24 '16 at 12:24
• Regarding again the question, you told that you didn't want to dirty hand-tweak with \raisebox. But, may I suggest a \raisebox with depth set to zero, and \height automatic, this used with a node.baseline as in my answer. For the use of \raisebox, I suggest something like \raisebox{0pt}[\height][0pt]{\mypicture}. It produces a correct input for you baseline, and avoid having big line skip. However, you will face text overlaping the picture sometimes. If you want, I may update my answer. – Damien Dtx Mar 14 '16 at 11:42

The general solution I needed was a combination of both baseline and the wonderful key use as bounding box: consider this :)

\documentclass[a4paper, 12pt]{report}

\usepackage{tikz}
\tikzset{x=1pt, y=1pt, z=1pt}

\begin{document}

\def\myfig{\begin{tikzpicture}[baseline=(base)] % choose baseline
% box dimensions
\path[draw, use as bounding box] (0, 0) rectangle (10, 15);
% set baseline
\coordinate (base) at (0, 5);
% actual content
\path[fill=blue] (0, 0) % a random path
..  controls (10, 10)
and (10, -10) ..
(10, 20) -- cycle;
% visualize baseline
\draw (0, 5) -- (10, 5);
\end{tikzpicture}}

Now I can define \emph{every} frea\myfig ng property of my tikz box!

\end{document}


Phew!