16

Is there any way of placing a tikzpicture code inline? Here is what I want to actuall achieve:

A convex function is denoted by "tikz code for convexity"

Someone told me this is possible. Also, in tikz-pgf tutorial I have seen many tikz codes inline. For example in the scaling section the author places a rotating ellipse inline (that is next to the text)

How can this be achieved?

3
  • You should take into account, that 'inline' means normally on the same baseline, so this might stretch the line height, since tikz figures are usually larger than 1ex
    – user31729
    Commented Jun 9, 2016 at 16:08
  • A tikzpicture is not really much different from the letter X, in that as far as TeX is concerned it is just a box that it is placed on the current baseline. Commented Jun 9, 2016 at 16:23
  • Thank you all either for your answers or your comments. I accept the second one but I guess that Rmano's answer will come in handy some time. :)
    – Tolaso
    Commented Jun 9, 2016 at 16:50

3 Answers 3

26

Either use tikzpicture as an environment or the \tikz inline macro.

But the problem with the line stretching is quite obvious!

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{shadings}

\begin{document}
A stupid text followed by \begin{tikzpicture}\draw[fill=red,line width=1pt]  circle(1ex);\end{tikzpicture}

A stupid text followed by \tikz{\draw[fill=red,line width=1pt]  circle(1ex);}

A stupid text followed by another stupid text followed

A stupid text followed by some dots \tikz{%
    \foreach \x /\cola in {1/blue,2/yellow,3/red,4/green,5/orange}  {%
      \shade[ball color=\cola] (\x,0)  circle(0.5ex*\x);
    }%
}
\end{document}

enter image description here

4
  • isn't just \tikz ... ; without the braces? (Seems to work both way, though). +1.
    – Rmano
    Commented Jun 9, 2016 at 16:25
  • @Rmano: Yes, you're right. I am not using \tikz... very often.
    – user31729
    Commented Jun 9, 2016 at 16:27
  • 1
    @Tolaso: You're welcome. Happy TeXing!
    – user31729
    Commented Jun 9, 2016 at 16:55
  • 1
    @to myself: use \protect before \tikz in captions
    – dEmigOd
    Commented Aug 16, 2021 at 8:43
16

Another example from a real-life document I have:

\documentclass{article}

\usepackage{tikz}

\newcommand{\ground}{%
    \begin{tikzpicture}[scale=0.5, baseline=-3mm, thick]
    \draw (0,0) -- +(0mm,-4.0mm) {
        [yshift=-4mm]
        +(-2mm,0mm) -- +(2mm,0mm)
                +(-1mm,-1mm) -- +(1mm,-1mm)
                +(-0.3mm,-2mm) -- +(0.3mm,-2mm)
        };
    \end{tikzpicture}%
}

\begin{document}

We have a text here, and then I refer to the ground (\ground) connection point in the instrument. Clearly, the \ground{} symbol will change the spacing... 
you can play with the \texttt{scale} and \texttt{baseline=-3mm} parameters in the definition\dots 
\end{document}

Output of the snippet above

2
  • Nicely done @Rmano.
    – Tolaso
    Commented Jun 9, 2016 at 16:49
  • 5
    +1 for the baseline option. Commented Feb 18, 2019 at 23:15
11

Here is a suggestion on how to place inline and the tikz code not be high enough from the text.

\raisebox{-2pt}{\tikz{\draw[line width=1pt, >->] (0, 0) arc (-180:0:8pt);}}

The output that gave me was the following, which is quite good I guess.

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .