TransWikia.com

Specifying a node at the center of each drawing

TeX - LaTeX Asked on July 14, 2021

Using the following modified code from this post

How can I specify a node at the center of each figure, so that they can be drawn related to the centers of each other, instead of position (0,0).

documentclass{article}
usepackage{tikz}
tikzset{
  big triangle/.pic={
  path[pic actions] (0,0) -- (2,0) -- (2,2) -- cycle;
  },
  medium triangle/.pic={
    path[pic actions] (0,0)  -- (1,1) -- (2,0) -- cycle;  
  },
  square/.pic={
    path[pic actions] (0,0) -- (1,0) -- (1,1) -- (0,1) -- cycle;
  },
  small triangle/.pic={
    path[pic actions] (0,0) -- (1,0) -- (1,1) -- cycle;
  },
  parallelogram/.pic={
    path[pic actions] (0,0) -- (1,0) -- (2,1) -- (1,1) -- cycle;
  }
  }
tikzset{
  tangram solution/.style={
      fill=none,
    draw=red,
    line width=.1mm
  },   
  tangram/.style={
  transform shape,
    tangram solution
  }
}
begin{document}
hskip -2cm
begin{tikzpicture}[scale=2]
path (0,0) pic[tangram,rotate=0] {big triangle}
--++(0:2) pic[tangram,rotate=0] {parallelogram}
--++(0:1) pic[tangram,rotate=0] {small triangle}
--++(0:1) pic[tangram,rotate=0] {square}
--++(0:1) pic[tangram,rotate=0] {medium triangle}
;
end{tikzpicture}
end{document}

enter image description here

One Answer

Here a manually computed coordinate shift is added to the path in each pic.

documentclass{article}
usepackage{tikz}
tikzset{
  big triangle/.pic={
    path[pic actions, shift={(-4/3,-2/3)}] (0,0) -- (2,0) -- (2,2) -- cycle;
    fill circle (1pt); % mark the "center", just for the test
  },
  medium triangle/.pic={
    path[pic actions, shift={(-1,-1/3)}] (0,0)  -- (1,1) -- (2,0) -- cycle;  
    fill circle (1pt);
  },
  square/.pic={
    path[pic actions, shift={(-.5,-.5)}] (0,0) -- (1,0) -- (1,1) -- (0,1) -- cycle;
    fill circle (1pt);
  },
  small triangle/.pic={
    path[pic actions, shift={(-2/3,-1/3)}] (0,0) -- (1,0) -- (1,1) -- cycle;
    fill circle (1pt);
  },
  parallelogram/.pic={
    path[pic actions, shift={(-1,-.5)}] (0,0) -- (1,0) -- (2,1) -- (1,1) -- cycle;
    fill circle (1pt);
  }
  }
tikzset{
  tangram solution/.style={
      fill=none,
    draw=red,
    line width=.1mm
  },   
  tangram/.style={
  transform shape,
    tangram solution
  }
}
begin{document}
hskip -2cm
begin{tikzpicture}[scale=2]
  path (0,0) pic[tangram,rotate=0] {big triangle}
    -- ++(0:2) pic[tangram,rotate=0] {parallelogram}
    -- ++(0:1) pic[tangram,rotate=0] {small triangle}
    -- ++(0:1) pic[tangram,rotate=0] {square}
    -- ++(0:1) pic[tangram,rotate=0] {medium triangle};
end{tikzpicture}
end{document}

enter image description here

Correct answer by muzimuzhi Z on July 14, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP