I have created a \newcommand with tikz-commands which will help drawing the red and blue squares with some special anchoring. When I call my command \placePic it works as it should. But if I call it again directly after, it will not draw the square. It will only draw it if I either have two semicolons or two new lines directly after the first call.

What is the problem with my command?

These variants create the right outcome with the blue square:

\placePic{red rectangle}{(base-circle)}{specialRectangle}{-left point}{red};;
\placePic{blue rectangle}{(base-circle)}{specialRectangle}{-right point}{blue}


\placePic{red rectangle}{(base-circle)}{specialRectangle}{-left point}{red}

\placePic{blue rectangle}{(base-circle)}{specialRectangle}{-right point}{blue}

Should look like this

But will look like this when not having either double semicolon or new lines:

But looks like this


% code by Andrew:
% https://tex.stackexchange.com/a/33765/13304

% #1 = name of new placement
% #2 = where to place (e.g. myA-star)
% #3 = pic type
% #4 = internal node to anchor (eg. -left point)
% #5 = pic actions
% #6 = shift
    \path pic (#1-PATH) at (0,0) {#3};
    \def\newX{\sbx - \sdx}
    \def\newY{\sby - \sdy}
    \path [pic shift={(\newX,\newY)}] pic[draw,#5] (#1) at (0,0) {#3};
    \node[draw,circle,inner sep=0,orange] at (\newX,\newY) {};

    pic shift/.store in=\shiftcoord,
    pic shift={(0,0)},
            \draw[very thick,pic actions] (0,0) rectangle (2,2);
            \node[very thick,fill=orange,circle,inner sep=0,minimum size=1mm] at (0,0) {};
            \node[draw,circle,minimum size=2mm,inner sep=0,thick,pic actions] (-circle) at (.5,.5) {};
            \node[draw,rectangle,minimum size=2mm,inner sep=0,thick,pic actions] (-square) at (.5,1.5) {};
            \node[draw,diamond,minimum size=2.5mm,inner sep=0,thick,pic actions] (-diamond) at (1.5,1.5) {};
            \node[draw,star,minimum size=2.5mm,inner sep=0,thick,pic actions] (-star) at (1.5,.5) {};
        \begin{scope}[shift={\shiftcoord},thick,pic actions]
            \path[pic actions] (-2.5mm,-2.5mm) rectangle +(5mm,5mm);
            \path[pic actions] (-2.5mm,0) -- +(-0.7mm,0) coordinate (-left point);
            \path[pic actions] (2.5mm,0) -- +(0.7mm,0) coordinate (-right point);
            \path[pic actions] (0,2.5mm) -- +(0,0.7mm) coordinate (-upper point);
            \path[pic actions] (0,-2.5mm) -- +(0,-0.7mm) coordinate (-lower point);
            \coordinate (-upper left) at (-2.5mm,2.5mm);
            \coordinate (-upper right) at (2.5mm,2.5mm);
            \coordinate (-lower left) at (-2.5mm,-2.5mm);
            \coordinate (-lower right) at (2.5mm,-2.5mm);

    % Help lines (grid)
    \draw[help lines,ultra thin,step=5mm] (0,0) grid (5,5);
    \draw[help lines,thin,step=10mm] (0,0) grid (5,5);

    \coordinate (origin) at (0,0);

    \pic[black] (base) at (origin) {myRectangle};
    \placePic{red rectangle}{(base-circle)}{specialRectangle}{-left point}{red};; % <-- ISSUE
    \placePic{as rectangle}{(base-circle)}{specialRectangle}{-right point}{red}


1 Answer 1


You put \newcommand{\placePic}[7] even if you're just using 5 arguments. So it took the two semicolon as arguments. Hence, changing it to \newcommand{\placePic}[5] will make it work!

You must log in to answer this question.

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