How can I improve my code to keep the relative positionning and handle the case above where i want to represent 2 or 3 out of 4 pics ? ![HedgeSymbolic1.png](/image?hash=2c5ffc16196bfed1ea1354a1d5517b210ac93a6873d83c299eea7d47bbe6206b) I can easily get individuals ![HedgeSymbolic2.png](/image?hash=11ada3cba6704033c984ac4de285ad35447896821e346b1b49c993600527dd8b) But as I reference things relative to other picture position, I obviously get stuck when I want 2 out of 4 next to each other. ![HedgeSymbolic3.png](/image?hash=257ca285f5029c1956beaf168190062ef363eeac502d76ae47ecc15e6a688f25) ``` \documentclass[tikz]{standalone} \usetikzlibrary{positioning} \newcommand{\Tikzhedgesymbolic}[1]{ \newif\ifOne \newif\ifTwo \newif\ifThree \newif\ifFour #1 \tikzset{font=\sffamily, Risk/.style={fill=brown!30, draw=brown!70}, Hedge/.style={fill=blue!50, dotted, fill opacity=0.3}, piclabel/.style 2 args=={text width = 6em,align=center,color=##1,,below =0.25 cm of ##2}, transformer/.style 2 args={draw, cylinder, gray!80, rotate=90, minimum height=##1, minimum width=##2}, Riskpic/.pic={\draw [Risk] (0,0)-- (2,0) -- (2,1) -- (0.90,0.85) -- (1,3) -- (0.05,3) -- cycle;}, Hedge1/.pic={\draw [Hedge] (0,0) -- (1,0) -- (1,3) -- (0,3) -- cycle;}, Hedge2/.pic={\draw [Hedge] (0,0) -- (2,0) -- (2,3) -- (0,3) -- cycle;}, Hedge3/.pic={\draw [Hedge] (0,0) -- (2,0) -- (2,1) -- (1,1) -- (1,3) -- (0,3) -- cycle;} } \ifOne \pic[local bounding box=A] at (0,0) {Riskpic}; \node[piclabel,red,below =0.25 cm of A] {Risque}; \fi \ifTwo \pic[local bounding box=B] at (3,0) {Riskpic}; \pic at (3,0) {Hedge1}; \node[piclabel,below =0.25 cm of B] {Sous-hedge vanille}; \fi \ifThree \pic[local bounding box=C] at (6,0) {Riskpic}; \pic at (6,0) {Hedge2}; \node[piclabel, below =0.25 cm of C] {Sur-hedge vanille}; \fi \ifFour \pic[local bounding box=D] at (9,0) {Riskpic}; \pic at (9,0) {Hedge3}; \node[piclabel, below =0.25 cm of D, blue] {Hedge exotique}; \fi } \begin{document} \tikz \Tikzhedgesymbolic{ \Onetrue \Twotrue \Threetrue \Fourtrue }; \tikz \Tikzhedgesymbolic{\Onetrue\Fourtrue}; %<- I would like poth picture to be next to each other \tikz \Tikzhedgesymbolic{\Onetrue}; \tikz \Tikzhedgesymbolic{\Twotrue}; \tikz \Tikzhedgesymbolic{\Threetrue}; \tikz \Tikzhedgesymbolic{\Fourtrue}; \end{document} ```
There are different ways to solve this. One is use a `matrix`. I also took the liberty to use `/.is if`. So you need only `\Tikzhedgesymbolic{1,2,3,4}` to get all of them. (It would be possible to extend this to `\Tikzhedgesymbolic{1,...,4}`, but as of now this is not built in.) ``` \documentclass[tikz]{standalone} \usetikzlibrary{positioning} \newcommand{\Tikzhedgesymbolic}[1]{ \newif\ifOne \newif\ifTwo \newif\ifThree \newif\ifFour \Onefalse\Twofalse\Threefalse\Fourfalse \tikzset{1/.is if=One,2/.is if=Two,3/.is if=Three,4/.is if=Four,#1} \tikzset{font=\sffamily, Risk/.style={fill=brown!30, draw=brown!70}, Hedge/.style={fill=blue!50, dotted, fill opacity=0.3}, piclabel/.style 2 args=={text width = 6em,align=center,color=##1,,below =0.25 cm of ##2}, transformer/.style 2 args={draw, cylinder, gray!80, rotate=90, minimum height=##1, minimum width=##2}, Riskpic/.pic={\draw [Risk] (0,0)-- (2,0) -- (2,1) -- (0.90,0.85) -- (1,3) -- (0.05,3) -- cycle;}, Hedge1/.pic={\draw [Hedge] (0,0) -- (1,0) -- (1,3) -- (0,3) -- cycle;}, Hedge2/.pic={\draw [Hedge] (0,0) -- (2,0) -- (2,3) -- (0,3) -- cycle;}, Hedge3/.pic={\draw [Hedge] (0,0) -- (2,0) -- (2,1) -- (1,1) -- (1,3) -- (0,3) -- cycle;} } \matrix[ampersand replacement=\&,column sep=2em]{ \ifOne \pic[local bounding box=A] {Riskpic}; \node[piclabel,red,below =0.25 cm of A] {Risque}; \& \fi \ifTwo \pic[local bounding box=B] {Riskpic}; \pic {Hedge1}; \node[piclabel,below =0.25 cm of B] {Sous-hedge vanille}; \& \fi \ifThree \pic[local bounding box=C] {Riskpic}; \pic {Hedge2}; \node[piclabel, below =0.25 cm of C] {Sur-hedge vanille};\& \fi \ifFour \pic[local bounding box=D] {Riskpic}; \pic {Hedge3}; \node[piclabel, below =0.25 cm of D, blue] {Hedge exotique}; \fi \\}; } \begin{document} \tikz \Tikzhedgesymbolic{1,2,3,4}; \tikz \Tikzhedgesymbolic{1,4}; %<- I would like poth picture to be next to each other \tikz \Tikzhedgesymbolic{1}; \tikz \Tikzhedgesymbolic{2}; \tikz \Tikzhedgesymbolic{3}; \tikz \Tikzhedgesymbolic{4}; \end{document} ``` ![Screen Shot 2020-12-23 at 9.21.56 AM.png](/image?hash=010908724a755175f793933808d422f63c2192d2460283ac01e7ffbdf7cf0379)