编辑图片 TIKZ 块

编辑图片 TIKZ 块

我正在绘制下图:

在此处输入图片描述

我想在创建块时将“PWM 逆变器”作为参数传递,但我无法做到这一点...另外,我想增加块内文本的大小。我该怎么做?

代码:

\documentclass[tikz,border=20pt]{standalone}

\usetikzlibrary{shapes,arrows}
\usetikzlibrary{decorations.pathreplacing}
\usetikzlibrary{babel}
\usetikzlibrary{calc,arrows.meta,patterns,backgrounds}
\usetikzlibrary{positioning}
\usetikzlibrary{fit}

\begin{document}
\tikzset{pics/inverter/.style 2 args={code={%
\path (-\pgfkeysvalueof{/tikz/inverter/width}/2,-\pgfkeysvalueof{/tikz/inverter/height}/2)
 node[above right] (bl) {#2}
 rectangle
(\pgfkeysvalueof{/tikz/inverter/width}/2,\pgfkeysvalueof{/tikz/inverter/height}/2)
 node[below left] (tr) {#1};
 \node[pic actions,inner sep=0pt,fit=(bl)(tr),path picture={\path[pic actions]
 (path picture bounding box.north west)
 -- (path picture bounding box.south east);}] 
 (\pgfkeysvalueof{/tikz/inverter/name}){};
 \node at (0,\pgfkeysvalueof{/tikz/inverter/height}/2) [rectangle, above]{PWM Inverter};
}},inverter/.cd,height/.initial=2cm,width/.initial=2cm,name/.initial=}

\begin{tikzpicture}
\path pic[draw,thick,rounded corners,text centered,inverter/name=inv] {inverter={$\sim$}{$\sim$}};
\end{tikzpicture}
\end{document}

答案1

出于某种原因,这段代码对我来说非常熟悉,因此很容易修改并为标题添加一个键。默认(或更准确地说是初始)值是,PWM Inverter但您可以更改它,如 MWE 中所示。

\documentclass[tikz,border=20pt]{standalone}
\usetikzlibrary{positioning}
\usetikzlibrary{fit}

\begin{document}
\tikzset{pics/inverter/.style 2 args={code={%
\path (-\pgfkeysvalueof{/tikz/inverter/width}/2,-\pgfkeysvalueof{/tikz/inverter/height}/2)
 node[above right,scale=2] (bl) {#2}
 rectangle
(\pgfkeysvalueof{/tikz/inverter/width}/2,\pgfkeysvalueof{/tikz/inverter/height}/2)
 node[below left,scale=2] (tr) {#1};
 \node[pic actions,inner sep=0pt,fit=(bl)(tr),path picture={\path[pic actions]
 (path picture bounding box.north west)
 -- (path picture bounding box.south east);}] 
 (\pgfkeysvalueof{/tikz/inverter/name}){};
 \node at (0,\pgfkeysvalueof{/tikz/inverter/height}/2) 
 [rectangle, above]{\pgfkeysvalueof{/tikz/inverter/title}};
}},inverter/.cd,height/.initial=2cm,width/.initial=2cm,name/.initial=,%
title/.initial=PWM Inverter}

\begin{tikzpicture}
\path pic[draw,thick,rounded corners,text centered,inverter/name=inv] {inverter={$\sim$}{$\sim$}}
(5,0) pic[draw,thick,rounded corners,text centered,inverter/.cd,name=inv2,title=some title]
{inverter={$\sim$}{$\sim$}};
\end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容