我正在尝试使用以下代码来获取图片:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{calc,shapes, positioning,intersections}
\begin{document}
\begin{tikzpicture}[node distance=-\pgflinewidth]
\coordinate (origin) at (0,0);
\coordinate (xEnd) at (0,4);
\coordinate (yEnd) at (10.5,0);
\tikzset{
mybox/.style = {
minimum height=#1,
minimum width=1.5cm,
inner sep=3pt,
rotate=90,
draw},
mybox/.default=10.5cm,
}
\draw[->,thick, name path=xaxis] (origin) -- node [above,rotate=90] {Processors} (xEnd);
\draw[->,thick, name path=yaxis] (origin) -- node [below] {Time} (yEnd);
\node (src) at (0.5,3) [mybox=0.4cm] {\large $src$};
\node (r0) [mybox=0.7cm,below=of src] {\large $radix_0$};
\node (r1) [mybox=0.7cm,below=of r0] {\large $radix_1$};
\node (r2) [mybox=0.7cm,below=of r1] {\large $radix_2$};
\node (r3) [mybox=0.7cm,below=of r2] {\large $radix_3$};
\node (r4) [mybox=0.7cm,below=of r3] {\large $radix_4$};
\node (r5) [mybox=0.7cm,below=of r4] {\large $radix_5$};
\node (r6) [mybox=0.7cm,below=of r5,xshift=-2cm] {\large $radix_6$};
\node (r7) [mybox=0.7cm,below=of r6] {\large $radix_7$};
\node (r8) [mybox=0.7cm,below=of r7] {\large $radix_8$};
\node (r9) [mybox=0.7cm,below=of r8] {\large $radix_9$};
\node (r10) [mybox=0.7cm,below=of r9] {\large $radix_{10}$};
\node (op) [mybox=0.4cm,below=of r10] {\large $output$};
\node (Bsrc) [mybox=0.4cm,below =of r5,fill=gray!50] {\large $src$};
\node (Br0) [mybox=0.7cm,below=of Bsrc,fill=gray!50] {\large $radix_0$};
\node (Br1) [mybox=0.7cm,below=of Br0,fill=gray!50] {\large $radix_1$};
\node (Br2) [mybox=0.7cm,below=of Br1,fill=gray!50] {\large $radix_2$};
\node (Br3) [mybox=0.7cm,below=of Br2,fill=gray!50] {\large $radix_3$};
\node (Br4) [mybox=0.7cm,below=of Br3,fill=gray!50] {\large $radix_4$};
\node (Br5) [mybox=0.7cm,below=of Br4,fill=gray!50] {\large $radix_5$};
\node (r6) at (0.65,1) [mybox=0.7cm,fill=gray!80] {\large $radix_6$};
\node (r7) [mybox=0.7cm,below=of r6,fill=gray!80] {\large $radix_7$};
\node (r8) [mybox=0.7cm,below=of r7,fill=gray!80] {\large $radix_8$};
\node (r9) [mybox=0.7cm,below=of r8,fill=gray!80] {\large $radix_9$};
\node (r10) [mybox=0.7cm,below=of r9,fill=gray!80] {\large $radix_{10}$};
\node (op) [mybox=0.4cm,below=of r10,fill=gray!80] {\large $output$};
\end{tikzpicture}
\end{document}
然后它生成了以下图像。现在,在生成的图像中,我发现对齐是错误的。您可以看到节点相对于其邻居在垂直方向上略有偏移。我该如何修复这个问题?
答案1
节点按线宽偏移(默认为 0.4pt)。将节点距离或线宽设置为 0 可消除偏移:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{calc,shapes, positioning,intersections}
\begin{document}
\begin{tikzpicture}[node distance=0pt]
\coordinate (origin) at (0,0);
\coordinate (xEnd) at (0,4);
\coordinate (yEnd) at (10.5,0);
\tikzset{
mybox/.style = {
minimum height=#1,
minimum width=1.5cm,
inner sep=3pt,
rotate=90,
line width=1pt,
draw},
mybox/.default=10.5cm,
}
\draw[->,thick, name path=xaxis] (origin) -- node [above,rotate=90] {Processors} (xEnd);
\draw[->,thick, name path=yaxis] (origin) -- node [below] {Time} (yEnd);
\node (src) at (0.5,3) [mybox=0.4cm] {\large $src$};
\node (r0) [mybox=0.7cm,below=of src.south] {\large $radix_0$};
\node (r1) [mybox=0.7cm,below=of r0] {\large $radix_1$};
\node (r2) [mybox=0.7cm,below=of r1] {\large $radix_2$};
\node (r3) [mybox=0.7cm,below=of r2] {\large $radix_3$};
\node (r4) [mybox=0.7cm,below=of r3] {\large $radix_4$};
\node (r5) [mybox=0.7cm,below=of r4] {\large $radix_5$};
\node (r6) [mybox=0.7cm,below=of r5,xshift=-2cm] {\large $radix_6$};
\node (r7) [mybox=0.7cm,below=of r6] {\large $radix_7$};
\node (r8) [mybox=0.7cm,below=of r7] {\large $radix_8$};
\node (r9) [mybox=0.7cm,below=of r8] {\large $radix_9$};
\node (r10) [mybox=0.7cm,below=of r9] {\large $radix_{10}$};
\node (op) [mybox=0.4cm,below=of r10] {\large $output$};
\node (Bsrc) [mybox=0.4cm,below =of r5,fill=gray!50] {\large $src$};
\node (Br0) [mybox=0.7cm,below=of Bsrc,fill=gray!50] {\large $radix_0$};
\node (Br1) [mybox=0.7cm,below=of Br0,fill=gray!50] {\large $radix_1$};
\node (Br2) [mybox=0.7cm,below=of Br1,fill=gray!50] {\large $radix_2$};
\node (Br3) [mybox=0.7cm,below=of Br2,fill=gray!50] {\large $radix_3$};
\node (Br4) [mybox=0.7cm,below=of Br3,fill=gray!50] {\large $radix_4$};
\node (Br5) [mybox=0.7cm,below=of Br4,fill=gray!50] {\large $radix_5$};
\node (r6) at (0.65,1) [mybox=0.7cm,fill=gray!80] {\large $radix_6$};
\node (r7) [mybox=0.7cm,below=of r6,fill=gray!80] {\large $radix_7$};
\node (r8) [mybox=0.7cm,below=of r7,fill=gray!80] {\large $radix_8$};
\node (r9) [mybox=0.7cm,below=of r8,fill=gray!80] {\large $radix_9$};
\node (r10) [mybox=0.7cm,below=of r9,fill=gray!80] {\large $radix_{10}$};
\node (op) [mybox=0.4cm,below=of r10,fill=gray!80] {\large $output$};
\end{tikzpicture}
\end{document}
答案2
PSTricks 解决方案:
\documentclass{article}
\usepackage{amsmath}
\usepackage{multido,pstricks}
\begin{document}
\begin{pspicture}(-0.55,-0.55)(13.7,5.2)
\psset{dimen = m}
\large
\psline{->}(0,0)(13.7,0)
\psline{->}(0,0)(0,5.2)
\rput(6.85,-0.4){Time}
\rput(-0.4,2.6){\rotateleft{Processors}}
\psframe[fillstyle = solid, fillcolor = gray](5.3,0.3)(6.3,2.3)
\rput(5.8,1.3){\rotateleft{output}}
\psframe(12.3,0.3)(13.3,2.3)
\rput(12.8,1.3){\rotateleft{output}}
\psframe(0.3,2.8)(1.3,4.8)
\rput(0.8,3.8){\rotateleft{src}}
\psframe[fillstyle = solid, fillcolor = gray](6.3,2.8)(7.3,4.8)
\rput(6.8,3.8){\rotateleft{src}}
\psframe[fillstyle = solid, fillcolor = gray](7.3,2.8)(8.3,4.8)
\rput(7.8,3.8){\rotateleft{$\text{radix}_{0}$}}
\multido{
\rA = 0.3+1,
\rB = 7.3+1,
\rC = 8.3+1,
\rD = 1.3+1,
\iB = 1+1,
\iA = 6+1
}{5}{
\psframe[fillstyle = solid, fillcolor = gray](\rA,0.3)(!\rA\space 1 add 2.3)
\rput(!\rA\space 0.5 add 1.3){\rotateleft{$\text{radix}_{\iA}$}}
\psframe(\rB,0.3)(!\rB\space 1 add 2.3)
\rput(!\rB\space 0.5 add 1.3){\rotateleft{$\text{radix}_{\iA}$}}
\psframe[fillstyle = solid, fillcolor = gray](\rC,2.8)(!\rC\space 1 add 4.8)
\rput(!\rC\space 0.5 add 3.8){\rotateleft{$\text{radix}_{\iB}$}}
\psframe(\rD,2.8)(!\rD\space 1 add 4.8)
\rput(!\rD\space 0.5 add 3.8){\rotateleft{$\text{radix}_{\iB}$}}
}
\end{pspicture}
\end{document}
答案3
dcmst 答案的变体,但代码更紧凑一些:
\documentclass[12pt,tikz,border=3mm]{standalone}
\usetikzlibrary{calc,chains,shapes,positioning,intersections}
\begin{document}
\begin{tikzpicture}[
node distance=3mm and 0mm,
start chain = going right,
mybox/.style = {
minimum height=19mm,
minimum width=7mm,
inner sep=3pt, outer sep=0pt,
font=\large,
line width=1pt,
draw,
on chain,
node contents={\rotatebox{90}{#1}},
},
]
\coordinate (origin) at (0,0);
\coordinate (xEnd) at (0,5);
\coordinate (yEnd) at (10.5,0);
\draw[->,thick,name path=xaxis] (origin) -- node [above,rotate=90] {Processors} (xEnd);
\draw[->,thick,name path=yaxis] (origin) -- node [below] {Time} (yEnd);
% first row
\node (src) at (0.5,3.3) [mybox=$src$];
\foreach \i in {0,1,...,5}
\node [mybox=$radix_{\i}$];
\node [mybox=$src$,fill=gray!80];
\foreach \i in {0,1,...,5}\node [mybox=$radix_{\i}$,fill=gray!80];
% second row
\node (r6) [mybox=$radix_{6}$,fill=gray!80,
below right=of src.south west];
\foreach \i in {7,8,9,10}
\node [mybox=$radix_{\i}$,fill=gray!80];
\node [mybox=$output$,fill=gray!80];
\node [mybox=$radix_6$,right=7mm];
\foreach \i in {7,8,9,10}
\node [mybox=$radix_{\i}$];
\node [mybox=$output$,fill=gray!80];
\end{tikzpicture}
\end{document}
上面我利用了chains
库和node contents
。结果与 Svend Tveskeag 提供的结果相同