1

Trying to draw two pictures within one tikzset. Why won't it draw myBalance?

\documentclass[a4paper]{article}
\usepackage[margin=10mm]{geometry}
\usepackage {array, tikz, amssymb}

\def \myScale {0.3}

\tikzset{ myBag/.pic={ \draw (-1,0) arc (180:360:1); \draw (1,0) arc (0:180:1 and 2); \draw [rounded corners=1 ] (0,2) -- (0.5,2.5) -- (-0.5,2.5) -- cycle; }

myBalance/.pic={ \draw (-3,0) -- (3,0); \draw[rounded corners=1] (0,0) -- (-0.2,-0.2) -- (0.2,-0.2) -- cycle; } }

\centering

\begin{document} \begin{center} \begin{tabular}{ m{8cm} m{0.5cm} m{8cm} } %\hline & & \ & & \ & & \ & & \ & & \ & & \

  1. & & 2) \

\begin{tikzpicture} \centering \pic [scale=\myScale] at (2,1) {myBag}; \pic [scale=\myScale] at (-3,0) {myBag}; \pic at (0,0) {myBalance}; \end{tikzpicture}

& & \

\end{tabular} \end{center} \end{document}

Roland
  • 6,655
Chau Tu
  • 21

2 Answers2

1

Also see here

\documentclass[a4paper]{article}
\usepackage[margin=10mm]{geometry}
\usepackage {array, tikz, amssymb}

\def \myScale {0.3}

\tikzset{ myBag/.pic={ \draw (-1,0) arc (180:360:1); \draw (1,0) arc (0:180:1 and 2); \draw [rounded corners=1 ] (0,2) -- (0.5,2.5) -- (-0.5,2.5) -- cycle;} } \tikzset{ myBalance/.pic={ \draw (-3,0) -- (3,0); \draw[rounded corners=1] (0,0) -- (-0.2,-0.2) -- (0.2,-0.2) -- cycle; } }

\centering

\begin{document} \begin{center} \begin{tabular}{ m{8cm} m{0.5cm} m{8cm} } %\hline & & \ & & \ & & \ & & \ & & \ & & \

  1. & & 2) \

\begin{tikzpicture} \centering \pic [scale=\myScale] at (2,1) {myBag}; \pic [scale=\myScale] at (-3,0) {myBag}; \pic at (0,0) {myBalance}; \end{tikzpicture}

& & \

\end{tabular} \end{center} \end{document}

enter image description here

Roland
  • 6,655
1

You should consider adding a comma between your two pics definitions.

\documentclass[a4paper]{article}
% https://tex.stackexchange.com/questions/633850/tikzset-multiple-pic
\usepackage[margin=10mm]{geometry}
\usepackage {array, tikz, amssymb}

\def \myScale {0.3}

\tikzset{ myBag/.pic={ \draw (-1,0) arc (180:360:1); \draw (1,0) arc (0:180:1 and 2); \draw [rounded corners=1 ] (0,2) -- (0.5,2.5) -- (-0.5,2.5) -- cycle; }, % <------------ Add a comma here! myBalance/.pic={ \draw (-3,0) -- (3,0); \draw[rounded corners=1] (0,0) -- (-0.2,-0.2) -- (0.2,-0.2) -- cycle; } }

\centering

\begin{document} \begin{center} \begin{tabular}{ m{8cm} m{0.5cm} m{8cm} } %\hline & & \ & & \ & & \ & & \ & & \ & & \

  1. & & 2) \

\begin{tikzpicture} \centering \pic [scale=\myScale] at (2,1) {myBag}; \pic [scale=\myScale] at (-3,0) {myBag}; \pic at (0,0) {myBalance}; \end{tikzpicture}

& & \

\end{tabular} \end{center} \end{document}

SebGlav
  • 19,186