如何设置空矩形节点的大小?

如何设置空矩形节点的大小?

我正在使用 TikZ 绘制 Petri 网。但是,根据我定义的样式,转换是具有 1:1 比例的矩形节点(实际上是正方形)。

我习惯使用更扁平的过渡,但我不知道如何设置它们的默认高度。我尝试使用yscale,但这会影响节点之间的距离。

\documentclass[a4paper, 12pt]{article}
\usepackage{tikz}
\usetikzlibrary{petri}
\tikzstyle{place}= [circle, draw=blue!50, fill=blue!20, thick, minimum size=0.6cm]
\tikzstyle{transition}= [rectangle, draw=black!50, fill=black!20, thick, minimum size=0.6cm]
\tikzstyle{pre}=    [<-, semithick]
\tikzstyle{post}=   [->, semithick]

\begin{document}
\begin{figure}[h]
\begin{center}
    \begin{tikzpicture}[node distance=2cm]
            \node[place] (p1){};
            \node[transition] (t1) [below of=p1]{}
                edge[pre] (p1);
            \node[place] (p2) [below of=t1]{};
            \node[transition] (t2) [below of=p2]{}
                edge[pre] (p2);
    \end{tikzpicture}
    \caption{Train n°1}
\end{center}
\end{figure}
\end{document}

答案1

类似这样的事?

\documentclass[a4paper, 12pt]{article}
\usepackage{tikz}
\usetikzlibrary{petri}
\tikzset{place/.style = {circle, draw=blue!50, fill=blue!20, thick, minimum size=0.6cm},
    transition/.style = {rectangle, draw=black!50, fill=black!20, thick, minimum width=0.6cm,
                        minimum height = 1cm},
    pre/.style =    {<-, semithick},
    post/.style =   {->, semithick}
}

\begin{document}
\begin{figure}[h]
\begin{center}
    \begin{tikzpicture}[node distance=2cm]
            \node[place] (p1){};
            \node[transition] (t1) [below of=p1]{}
                edge[pre] (p1);
            \node[place] (p2) [below of=t1]{};
            \node[transition] (t2) [below of=p2]{}
                edge[pre] (p2);
    \end{tikzpicture}
    \caption{Train n°1}
\end{center}
\end{figure}
\end{document}

在此处输入图片描述

minimum size将宽度和高度设置为相等,这样您就会得到一个正方形。相反,您可以通过minimum width=<dimen>和分别设置宽度和高度minimum height = <dimen>

相关内容