Tikz /.style 有两个参数

Tikz /.style 有两个参数

如何将两个参数传递给 tikz 样式?我想做这样的事情:

\begin{tikzpicture}[
    transformer/.style={draw, cylinder, gray!80, rotate=90, minimum height=#1, minimum width=#2},

然后,我想在节点中使用这种样式:

\node [transformer{2.3cm}{1cm}] () at (0,0.6) {};

答案1

\documentclass{article}
\usepackage{tikz} 
\usetikzlibrary{shapes}  
\begin{document}
 \thispagestyle{empty} 

 \begin{tikzpicture}[
    transformer/.style 2 args={draw, cylinder, gray!80, rotate=90, minimum height=#1, minimum width=#2}]

\node [transformer={2.3cm}{1cm}] () at (0,0.6) {};
\end{tikzpicture}  
\end{document} 

相关内容