I have a small image I want to reuse in another tikz picture.

Let's say file img.tex contains:

    \draw (0,0) circle (1);

and I want it to appear in several places in an other image


    \draw (0,0) grid (10, 1);
    \foreach \x in {2,5,9}
        \node at (\x - 0.5, 0.5) {\mycuteimage{0.1}};

Can I somehow set the color of the inserted image, say sometimes red, sometimes blue?



I've tried to use

{\color{blue} \mycuteimage{0.1}}

but it only changes the color of lines I didn't specify a color for, i.e., if, some elements were red in the original image they will remain red.

  • Why do you have to make a whole img.tex just to contain a figure? I think you should add the figure directly to the command definition. – user156344 Feb 27 '19 at 12:32
  • i intend to reuse it in more images – dEmigOd Feb 27 '19 at 13:11
  • This nests tikzpictures, which should be avoided. You could use a pic. – user121799 Feb 27 '19 at 13:58

Your proposal nests tikzpictures, which should be avoided. TikZ has pics for such purposes.

my cute pic/.style={code={
    \draw (0,0) circle (1);

    \draw (0,0) grid (10, 1);
    \foreach \X [count=\Y starting from 0]in {2,5,9}
        \pic at (\X - 0.5, 0.5) [scale=0.1,color=\mycolor]{my cute pic};

enter image description here

pics also take parameters.

| improve this answer | |
  • And the result is ... the same. It colors only color-unspecified lines. So, if I have colored lines in original code - it stays the same. On the other hand \input works in code section !! – dEmigOd Feb 28 '19 at 8:25

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.