我对 Latex 还很陌生,正在尝试创建流程图。D1 的两个节点完全重叠。使用自定义命令定义的图表本身就是 tikz 图片。我遇到的另一个问题是,我希望图像的标签位于顶部,但无论我怎么尝试,我都无法做到这一点。
\documentclass{article}
\usepackage{graphicx}
\usepackage{tikz}
\begin{document}
\definecolor{cffffff}{RGB}{255,255,255}
\definecolor{cff6600}{RGB}{255,102,0}
\definecolor{cff8080}{RGB}{255,128,128}
\newcommand{\diagramA}{\begin{tikzpicture}
\begin{scope}[shift={(86.24562,-1.70874)}]
\path[fill=cffffff,fill opacity=0.996,rounded corners=0.0000cm]
(19.1071,13.4336) rectangle (83.1071,77.4336);
\path[draw=black,line join=miter,line cap=butt,fill opacity=0.750,even odd
rule,line width=0.100pt] (19.1071,13.4336) --
(19.1071,77.4336)(27.1071,13.4336) -- (27.1071,77.4336)(35.1071,13.4336) --
(35.1071,77.4336)(43.1071,13.4336) -- (43.1071,77.4336)(51.1071,13.4336) --
(51.1071,77.4336)(59.1071,13.4336) -- (59.1071,77.4336)(67.1071,13.4336) --
(67.1071,77.4336)(75.1071,13.4336) -- (75.1071,77.4336)(83.1071,13.4336) --
(83.1071,77.4336)(19.1071,13.4336) -- (83.1071,13.4336)(19.1071,21.4336) --
(83.1071,21.4336)(19.1071,29.4336) -- (83.1071,29.4336)(19.1071,37.4336) --
(83.1071,37.4336)(19.1071,45.4336) -- (83.1071,45.4336)(19.1071,53.4336) --
(83.1071,53.4336)(19.1071,61.4336) -- (83.1071,61.4336)(19.1071,69.4336) --
(83.1071,69.4336)(19.1071,77.4336) -- (83.1071,77.4336);
\end{scope}
\path[draw=black,fill=cff6600,miter limit=4.00,fill opacity=0.996,line
width=0.160pt,rounded corners=0.0000cm] (105.3755,11.7660) rectangle
(113.3755,27.7660);
\path[draw=black,fill=cff8080,miter limit=4.00,fill opacity=0.996,line
width=0.114pt,rounded corners=0.0000cm] (113.3540,11.8100) rectangle
(121.4116,19.8675);
\end{tikzpicture}}
\newcommand{\diagramBa}{
\definecolor{cffffff}{RGB}{255,255,255}
\definecolor{cff0000}{RGB}{255,0,0}
\definecolor{cff6600}{RGB}{255,102,0}
\begin{tikzpicture}[y=0.80pt, x=0.80pt, yscale=-1.000000, xscale=1.000000, inner sep=0pt, outer sep=0pt]
\begin{scope}[shift={(86.67178,67.24995)}]
\path[fill=cffffff,fill opacity=0.996,rounded corners=0.0000cm]
(19.1071,13.4336) rectangle (83.1071,77.4336);
\path[draw=black,line join=miter,line cap=butt,fill opacity=0.750,even odd
rule,line width=0.100pt] (19.1071,13.4336) --
(19.1071,77.4336)(27.1071,13.4336) -- (27.1071,77.4336)(35.1071,13.4336) --
(35.1071,77.4336)(43.1071,13.4336) -- (43.1071,77.4336)(51.1071,13.4336) --
(51.1071,77.4336)(59.1071,13.4336) -- (59.1071,77.4336)(67.1071,13.4336) --
(67.1071,77.4336)(75.1071,13.4336) -- (75.1071,77.4336)(83.1071,13.4336) --
(83.1071,77.4336)(19.1071,13.4336) -- (83.1071,13.4336)(19.1071,21.4336) --
(83.1071,21.4336)(19.1071,29.4336) -- (83.1071,29.4336)(19.1071,37.4336) --
(83.1071,37.4336)(19.1071,45.4336) -- (83.1071,45.4336)(19.1071,53.4336) --
(83.1071,53.4336)(19.1071,61.4336) -- (83.1071,61.4336)(19.1071,69.4336) --
(83.1071,69.4336)(19.1071,77.4336) -- (83.1071,77.4336);
\end{scope}
\path[draw=black,fill=cff0000,miter limit=4.00,fill opacity=0.996,line
width=0.160pt,rounded corners=0.0000cm] (105.8017,80.7247) rectangle
(113.8017,96.7247);
\path[draw=black,fill=cff6600,miter limit=4.00,fill opacity=0.996,line
width=0.160pt,rounded corners=0.0000cm] (113.8223,80.7392) rectangle
(121.8223,96.7392);
\end{tikzpicture}
}
\newcommand{\diagramBb}{
\definecolor{cffffff}{RGB}{255,255,255}
\definecolor{cff0000}{RGB}{255,0,0}
\definecolor{cff6600}{RGB}{255,102,0}
\definecolor{cff8080}{RGB}{255,128,128}
\begin{tikzpicture}[y=0.80pt, x=0.80pt, yscale=-1.000000, xscale=1.000000, inner sep=0pt, outer sep=0pt]
\begin{scope}[shift={(86.66259,133.81742)}]
\path[fill=cffffff,fill opacity=0.996,rounded corners=0.0000cm]
(19.1071,13.4336) rectangle (83.1071,77.4336);
\path[draw=black,line join=miter,line cap=butt,fill opacity=0.750,even odd
rule,line width=0.100pt] (19.1071,13.4336) --
(19.1071,77.4336)(27.1071,13.4336) -- (27.1071,77.4336)(35.1071,13.4336) --
(35.1071,77.4336)(43.1071,13.4336) -- (43.1071,77.4336)(51.1071,13.4336) --
(51.1071,77.4336)(59.1071,13.4336) -- (59.1071,77.4336)(67.1071,13.4336) --
(67.1071,77.4336)(75.1071,13.4336) -- (75.1071,77.4336)(83.1071,13.4336) --
(83.1071,77.4336)(19.1071,13.4336) -- (83.1071,13.4336)(19.1071,21.4336) --
(83.1071,21.4336)(19.1071,29.4336) -- (83.1071,29.4336)(19.1071,37.4336) --
(83.1071,37.4336)(19.1071,45.4336) -- (83.1071,45.4336)(19.1071,53.4336) --
(83.1071,53.4336)(19.1071,61.4336) -- (83.1071,61.4336)(19.1071,69.4336) --
(83.1071,69.4336)(19.1071,77.4336) -- (83.1071,77.4336);
\end{scope}
\path[draw=black,fill=cff0000,miter limit=4.00,fill opacity=0.996,line
width=0.160pt,rounded corners=0.0000cm] (105.7925,147.2922) rectangle
(113.7925,163.2922);
\path[cm={{0.0,1.0,-1.0,0.0,(0.0,0.0)}},draw=black,fill=cff6600,miter
limit=4.00,fill opacity=0.996,line width=0.160pt,rounded corners=0.0000cm]
(147.2979,-129.8177) rectangle (155.2979,-113.8177);
\path[draw=black,fill=cff8080,miter limit=4.00,fill opacity=0.996,line
width=0.114pt,rounded corners=0.0000cm] (105.5415,163.1772) rectangle
(113.5991,171.2347);
\end{tikzpicture}
}
\begin{tikzpicture}[y=0.80pt, x=0.80pt, yscale=-1.000000, xscale=1.000000,
inner sep=0pt, outer sep=0pt, node distance=2cm]
\tikzstyle{block} = [rectangle, rounded corners, minimum width=3cm, minimum height=1cm,text centered, draw=black, very thin, inner sep=2mm]
\node [block] (pos) {Possibilities};
\node [block, below of=pos] (D1) {
1:\linebreak[4]
\diagramA
};
\node [block, below of=D1] (D2a) {
1:\linebreak[4]
\diagramBa
};
\node [block, below of=D1] (D2b) {
1:\linebreak[4]
\diagramBb
};
\end{tikzpicture}
\end{document}
另外,我认为我做事的方式并不理想,也许您可以指出一些我可以做得更好的事情。
答案1
看看您对流程图的以下重新编码是否可以接受:
\documentclass[tikz, margin=3.141592mm]{standalone}
\usetikzlibrary{calc, fit, positioning}
\begin{document}
\begin{tikzpicture}[
node distance = 4mm and 6mm,
grid/.style = {draw=gray, very thin, minimum size=2.4mm,
inner sep=0pt, outer sep=0pt},
box/.style args = {#1/#2}{grid, above right,
minimum height=#1*2.4mm, minimum width=#2*2.4mm},% <--- size of grid boxes is
% determined by multiplicators of % grid cells size
% used are in grid cells coloring
mypic/.pic = {
\foreach \x in {1,...,8}
{ \foreach \y in {1,...,8}
{
\node [grid] (n\x\y) at (.24*\x,.24*\y) {}; % <--- positions of grid boxes
\coordinate (-g\x\y) at (n\x\y.south west); % <--- coordinates used in grid boxes coloring
}
}
\node (n0) [left=of n11] {1:};
\node (f) [draw, very thin, rounded corners, inner sep=2mm, fit =(n0) (n88)] {};
\coordinate (-w) at (f.west); % <-- coordinates of pic,
% needed at eventual drawing of lines between pic
\coordinate (-e) at (f.east);
\coordinate (-n) at (f.north);
\coordinate (-s) at (f.south);
},% end of pic
N/.style={grid, path picture={\pic {mypic};}}
]
\pic (p1) {mypic};
\node [box=1/1,fill=red!30] at (p1-g21) {}; % positioning of \pic
\node [box=2/1,fill=orange] at (p1-g11) {};
\pic (p2) at (-2,-2.8) {mypic}; % positioning of \pic is estimated:
% x distance ~ pic width/2,
% y distance~ pic height/2with
\node [box=1/1,fill=red!30] at (p2-g18) {};
\node [box=2/1,fill=orange] at (p2-g27) {};
\pic (p3) at ( 2,-2.8) {mypic};
\node [box=1/2,fill=red!30] at (p3-g18) {};
\node [box=1/1,fill=orange] at (p3-g17) {};
\path let \p1 = ($(p1-w)-(p1-e)$),
\n1 = {veclen(\x1,\y1) } in
node [minimum width=\n1,
draw=gray, very thin, rounded corners, inner sep=2mm,
above=of p1-n] {Possibilities};
\end{tikzpicture}
\end{document}
现在代码相当简短和清晰。节点的定位使用绝对坐标,这并不难确定(参见代码中的注释)。结果是:
网格中的彩色框可能位置不正确,也没有所需的颜色。这个我留给你了。从给出的例子中,应该可以直接识别网格中框的位置,你喜欢的颜色和定义所需的颜色
当然,还有其他方法来定义你的节点......
编辑:
\pic
(代表小图像)是绘制小图像的好方法,\pic {<name>};
可以将其包含到某些主(更大)tikz
图片中。- 包含
\pic
在其样式定义中定义(对于它,我选择名称˙mypic, but you can select own name which is more meaningful to you). definition contains array of nodes
grid, which has name
n\xy
,其中\x
和y
通过使用循环确定。 - 数组第一列中的名称从
n11
(底部)到n18
(顶部)。 - 节点
n0
,其中1:
包含相对于节点的定位n11
。如果您想改变这个位置,您可以选择其他节点(例如n18
。 - 节点样式
box
是为数组中的节点着色而定义的。它们的大小可以通过乘数器简单设置,乘数器决定了grid
将覆盖多少个节点 - 用于节点定位的
box
确定坐标-g\x\y
。 - 它的行为不像标准节点,因此您需要在图像中放置它们时进行一些敲击(因此我使用绝对坐标)