我正在尝试使用内部存储符号 (http://www.smartdraw.com/flowchart/flowchart-symbols.htm)。我的第一次尝试结果是:
\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{shapes}
\usetikzlibrary{arrows}
\begin{document}
\begin{tikzpicture}[auto]
\tikzstyle{internalStorageTop} = [draw, thick, rectangle split, rectangle split horizontal,rectangle split parts=2]
\tikzstyle{internalStorage} = [draw, thick, rectangle split, rectangle split horizontal,rectangle split parts=2, align=center]
\tikzstyle{process} = [rectangle, draw, thick, align=center]
\tikzstyle{line} = [draw, thick, -triangle 45];
\matrix [column sep={10mm},row sep=10mm]{
& \node [process] (generate) {process}; & \\
& \node [internalStorageTop] (split) {\nodepart[text width=40mm]{two}\phantom{internal storage}}; & \\[-10.25mm]
& \node [internalStorage] {\nodepart[text width=40mm]{two}{internal storage\\ internal storage}}; & \\
};
\tikzstyle{every path}=[line]
\path (generate) -- (split);
\end{tikzpicture}
\end{document}
但这看起来有点丑。您对如何正确生成此符号有什么建议吗?
答案1
它并不完全简单,但它现在是一个单个节点:
\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{shapes,arrows,calc,backgrounds}
\newlength{\tempdima}
\newlength{\tempdimb}
\tikzset{storage gap/.initial=1em}
\pgfdeclareshape{storage}{
\savedanchor{\northeast}{
\setlength{\tempdima}{\pgfkeysvalueof{/tikz/storage gap}}
\tempdima=0.5\tempdima
\tempdimb=\tempdima
\addtolength{\tempdima}{\pgfkeysvalueof{/pgf/inner xsep}}
\addtolength{\tempdimb}{\pgfkeysvalueof{/pgf/inner ysep}}
\pgfpoint{\dimexpr \tempdima + .5\wd\pgfnodeparttextbox}{\dimexpr \tempdimb + 0.5\ht\pgfnodeparttextbox +.5\dp\pgfnodeparttextbox}}
\savedanchor{\southwest}{
\setlength{\tempdima}{\pgfkeysvalueof{/tikz/storage gap}}
\tempdima=0.5\tempdima
\tempdimb=\tempdima
\addtolength{\tempdima}{\pgfkeysvalueof{/pgf/inner xsep}}
\addtolength{\tempdimb}{\pgfkeysvalueof{/pgf/inner ysep}}
\pgfpoint{\dimexpr -\tempdima -.5\wd\pgfnodeparttextbox}{\dimexpr -\tempdimb -.5\ht\pgfnodeparttextbox -.5\dp\pgfnodeparttextbox}}
\anchor{center}{\pgfpointorigin} % within the node, (0,0) is the center
\inheritanchorborder[from=rectangle]
\inheritanchor[from=rectangle]{north}
\inheritanchor[from=rectangle]{north west}
\inheritanchor[from=rectangle]{north east}
\inheritanchor[from=rectangle]{center}
\inheritanchor[from=rectangle]{west}
\inheritanchor[from=rectangle]{east}
\inheritanchor[from=rectangle]{mid}
\inheritanchor[from=rectangle]{mid west}
\inheritanchor[from=rectangle]{mid east}
\inheritanchor[from=rectangle]{base}
\inheritanchor[from=rectangle]{base west}
\inheritanchor[from=rectangle]{base east}
\inheritanchor[from=rectangle]{south}
\inheritanchor[from=rectangle]{south west}
\inheritanchor[from=rectangle]{south east}
\anchor{text} % this is used to center the text in the node
{\setlength{\tempdima}{\pgfkeysvalueof{/tikz/storage gap}}
\pgfpoint{\dimexpr 0.5\tempdima -.5\wd\pgfnodeparttextbox}{\dimexpr -0.5\tempdima -.5\ht\pgfnodeparttextbox+.5\dp\pgfnodeparttextbox }}
\backgroundpath{% draw border etc
\pgfpathrectanglecorners{\southwest}{\northeast}
\pgfextractx{\tempdima}{\southwest}
\pgfextracty{\tempdimb}{\southwest}
\addtolength{\tempdima}{\pgfkeysvalueof{/tikz/storage gap}}
\pgfpathmoveto{\pgfpoint{\tempdima}{\tempdimb}}
\pgfextracty{\tempdimb}{\northeast}
\pgfpathlineto{\pgfpoint{\tempdima}{\tempdimb}}
\addtolength{\tempdimb}{-\pgfkeysvalueof{/tikz/storage gap}}
\pgfextractx{\tempdima}{\southwest}
\pgfpathmoveto{\pgfpoint{\tempdima}{\tempdimb}}
\pgfextractx{\tempdima}{\northeast}
\pgfpathlineto{\pgfpoint{\tempdima}{\tempdimb}}
}}
\begin{document}
\begin{tikzpicture}[auto]
\tikzstyle{process} = [rectangle, draw, thick, align=center]
\tikzstyle{internalStorage} = [storage,draw, thick, align=center]
\tikzstyle{line} = [draw, thick, -triangle 45];
\matrix [column sep={10mm},row sep=10mm]{
& \node [process] (generate) {process}; & \\
& \node [internalStorage,fill=white,text width=1in] (split) {internal storage\\ internal storage}; & \\
};
\tikzstyle{every path}=[line]
\path (generate) -- (split);
\begin{scope}[on background layer]
\draw [draw=none,fill=green!15] ($(generate.north west)+(-1.2cm,0.4cm)$) node[anchor=north west] {Fig. 7} rectangle ($(split.south east)+(0.8cm,-0.1cm)$);
\end{scope}
\end{tikzpicture}
\end{document}
答案2
这就是我想要的。非常感谢。我还有两件事。1. 有没有办法合并多行文本。2. 当项目放在彩色框上时,如何使背景变为白色。这是我的示例:
\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{shapes,arrows,calc,backgrounds}
\newlength{\tempdima}
\newlength{\tempdimb}
\tikzset{gap/.initial=1em}
\tikzset{linethickness/.initial=0.75pt}
\pgfdeclareshape{internalStorage}{
\savedanchor{\northeast}{
\setlength{\tempdima}{\pgfkeysvalueof{/tikz/gap}}
\tempdima=0.5\tempdima
\tempdimb=\tempdima
\addtolength{\tempdima}{\pgfkeysvalueof{/pgf/inner xsep}}
\addtolength{\tempdimb}{\pgfkeysvalueof{/pgf/inner ysep}}
\pgfpoint{\dimexpr \tempdima + .5\wd\pgfnodeparttextbox}{\dimexpr \tempdimb + .5\ht\pgfnodeparttextbox}}
\savedanchor{\southwest}{
\setlength{\tempdima}{\pgfkeysvalueof{/tikz/gap}}
\tempdima=0.5\tempdima
\tempdimb=\tempdima
\addtolength{\tempdima}{\pgfkeysvalueof{/pgf/inner xsep}}
\addtolength{\tempdimb}{\pgfkeysvalueof{/pgf/inner ysep}}
\pgfpoint{\dimexpr -\tempdima -.5\wd\pgfnodeparttextbox}{\dimexpr -\tempdimb -.5\ht\pgfnodeparttextbox}}
\anchor{center}{\pgfpointorigin} % within the node, (0,0) is the center
\inheritanchorborder[from=rectangle]
\inheritanchor[from=rectangle]{north}
\inheritanchor[from=rectangle]{north west}
\inheritanchor[from=rectangle]{north east}
\inheritanchor[from=rectangle]{center}
\inheritanchor[from=rectangle]{west}
\inheritanchor[from=rectangle]{east}
\inheritanchor[from=rectangle]{mid}
\inheritanchor[from=rectangle]{mid west}
\inheritanchor[from=rectangle]{mid east}
\inheritanchor[from=rectangle]{base}
\inheritanchor[from=rectangle]{base west}
\inheritanchor[from=rectangle]{base east}
\inheritanchor[from=rectangle]{south}
\inheritanchor[from=rectangle]{south west}
\inheritanchor[from=rectangle]{south east}
\anchor{text} % this is used to center the text in the node
{\setlength{\tempdima}{\pgfkeysvalueof{/tikz/gap}}
\pgfpoint{\dimexpr 0.5\tempdima -.5\wd\pgfnodeparttextbox}{\dimexpr -0.5\tempdima -.5\ht\pgfnodeparttextbox}}
\backgroundpath{% draw border etc
\pgfsetlinewidth{\pgfkeysvalueof{/tikz/linethickness}}
\pgfpathrectanglecorners{\southwest}{\northeast}
\pgfextractx{\tempdima}{\southwest}
\pgfextracty{\tempdimb}{\southwest}
\addtolength{\tempdima}{\pgfkeysvalueof{/tikz/gap}}
\pgfpathmoveto{\pgfpoint{\tempdima}{\tempdimb}}
\pgfextracty{\tempdimb}{\northeast}
\pgfpathlineto{\pgfpoint{\tempdima}{\tempdimb}}
\addtolength{\tempdimb}{-\pgfkeysvalueof{/tikz/gap}}
\pgfextractx{\tempdima}{\southwest}
\pgfpathmoveto{\pgfpoint{\tempdima}{\tempdimb}}
\pgfextractx{\tempdima}{\northeast}
\pgfpathlineto{\pgfpoint{\tempdima}{\tempdimb}}
\pgfusepath{draw}
}}
\begin{document}
\begin{tikzpicture}[auto]
\tikzstyle{process} = [rectangle, draw, thick, align=center]
\tikzstyle{line} = [draw, thick, -triangle 45];
\matrix [column sep={10mm},row sep=10mm]{
& \node [process] (generate) {process}; & \\
& \node [internalStorage,fill=white] (split) {internal storage\\ internal storage}; & \\
};
\tikzstyle{every path}=[line]
\path (generate) -- (split);
\begin{scope}[on background layer]
\draw [draw=none,fill=green!15] ($(generate.north west)+(-1.2cm,0.4cm)$) node[anchor=north west] {Fig. 7} rectangle ($(split.south east)+(0.8cm,-0.1cm)$);
\end{scope}
\end{tikzpicture}
\end{document}
我很感激任何建议。此致