1

I'm drawing the following diagram:

enter image description here

And I'd like to pass "PWM Inverter" as a parameter when creating the block, which I couldn't do... Also, I'd like to increase the size of the text inside the block. How do I do it?

The code:

\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}
4

For some reason this code looks very familiar to me so it was easy to modify and to add a key for the title. The default (or, more precisely, initial) value is PWM Inverter but you can change it, as illustrated in the 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}

enter image description here

  • How could we increase the text size inside the block (I mean turning "~" bigger)? – Clecio Jung Aug 16 '19 at 15:10
  • 1
    @ClecioJung Add scale=2 or something like that to the options of the node. – Schrödinger's cat Aug 16 '19 at 15:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.