저는 다음 다이어그램을 그리고 있습니다.
그리고 블록을 생성할 때 "PWM Inverter"를 파라미터로 전달하고 싶은데, 그렇게 할 수 없었는데요... 그리고 블록 내부의 텍스트 크기를 늘리고 싶습니다. 어떻게 해야 하나요?
코드:
\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}