我正在尝试创建一个 Tikz 节点,其中包含一些具有“数据存储”流程图形状的文本:
这就是我正在构建的内容:
\usepackage{tikz}
\usetikzlibrary{shapes.geometric}
\tikzstyle{storage} = [rectangle, minimum width=3cm, minimum height=1cm, text width=3cm, text centered, draw=black]
\begin{tikzpicture}[node distance=2cm]
\node (sto1) [storage] {Some text}
\end{tikzpicture}
答案1
\documentclass[tikz,border=3.14mm]{standalone}
\makeatletter % https://tex.stackexchange.com/a/241737/121799
\tikzset{pics/named scope code/.style={code={\tikz@fig@mustbenamed%
\begin{scope}[local bounding box/.expanded=\tikz@fig@name]#1\end{scope}%
}}}
\makeatother
\tikzset{pics/.cd,
pic memory/.style={named scope code={
\filldraw[fill=blue!30!gray!50](0,0) arc(90:270:0.5 and 1) --++(4,0) arc(-90:-270:0.5 and 1) --cycle
node[pos=.6,below={1cm},anchor=center] {#1};
}}
}
\begin{document}
\begin{tikzpicture}
\pic (memory1) at (0,0) {pic memory=Test text};
\draw[thick,blue,-latex] (memory1.west) -- ++(-2,0);
\draw[thick,red,-latex] (memory1.north) -- ++(-1,2);
\end{tikzpicture}
\end{document}
答案2
可以使用节点完成类似这样的操作rounded rectangle
:
\documentclass[tikz, border=1mm]{standalone}
\usetikzlibrary{shapes.misc}
\begin{document}
\begin{tikzpicture}[
datastore/.style={draw, rounded rectangle, rounded rectangle east arc=concave, rounded rectangle arc length=150}
]
\node[datastore, minimum width=4cm, minimum height=1.5cm, fill=cyan!30, draw=cyan!70!black]{Example};
\end{tikzpicture}
\end{document}
答案3
绘制“存储”的流程图符号,类似于使用 tikz 显示流程图的“显示”形状,您可以使用以下代码。
\documentclass{article}
\usepackage[margin=0.5in]{geometry}
\usepackage{pgfplots}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric, arrows}
\tikzstyle{process} = [rectangle, minimum width=3cm, minimum height=1cm, text centered, text
width=3cm, draw=orange, fill=orange!20]
\tikzstyle{arrow} = [thick,->,>=stealth]
\makeatletter
\pgfdeclareshape{display}
{
\inheritsavedanchors[from=rectangle] % this is nearly a rectangle
\inheritanchorborder[from=rectangle]
\inheritanchor[from=rectangle]{north}
\inheritanchor[from=rectangle]{west}
\inheritanchor[from=rectangle]{east}
\inheritanchor[from=rectangle]{south}
\inheritanchor[from=rectangle]{center}
\inheritbackgroundpath[from=rectangle]
\backgroundpath{
% points
\southwest \pgf@xa=\pgf@x \pgf@ya=\pgf@y
\northeast \pgf@xb=\pgf@x \pgf@yb=\pgf@y
% dimensions
\pgfmathsetlength{\pgfutil@tempdima}{\pgf@xb-\pgf@xa}
\pgfmathsetlength{\pgfutil@tempdimb}{\pgf@yb-\pgf@ya}
% path
\pgfpathmoveto{\pgfpointadd{\pgfqpoint{\pgf@xa}{\pgf@ya}}{\pgfqpoint{-0.2\pgfutil@tempdima}
{0pt}}}
\pgfpatharc{-90}{90}{0.2\pgfutil@tempdima and 0.5\pgfutil@tempdimb}
\pgfpathlineto{\pgfpointadd{\pgfqpoint{\pgf@xa}{\pgf@yb}}{\pgfqpoint{0.8\pgfutil@tempdima}
{0pt}}}
\pgfpathlineto{\pgfpointadd{\pgfqpoint{\pgf@xb}{\pgf@yb}}{\pgfqpoint{-0.2\pgfutil@tempdima}
{0pt}}}
\pgfpatharc{90}{-90}{0.2\pgfutil@tempdima and 0.5\pgfutil@tempdimb}
\pgfpathlineto{\pgfpointadd{\pgfqpoint{\pgf@xb}{\pgf@ya}}{\pgfqpoint{-0.2\pgfutil@tempdima}
{0pt}}}
\pgfpathlineto{\pgfpointadd{\pgfqpoint{\pgf@xa}{\pgf@ya}}{\pgfqpoint{0.8\pgfutil@tempdima}
{0pt}}}
\pgfpathclose
}
}
\makeatother
\tikzstyle{disp} = [display, draw, fill = cyan!20,
text width = 5em, align=center, minimum height = 3.5em]
\pgfplotsset{width=10cm, compat=1.9}
\begin{document}
\begin{tikzpicture}[node distance=2cm]
\node (disp) [disp] {Storage};
\node (pro2b) [process, right of = disp, xshift=2cm] {Process 2b};
\draw [arrow] (disp) -- (pro2b);
\end{tikzpicture}
\end{document}