![pdflatex 输出中的“颗粒状”tikz 节点文本](https://linux22.com/image/377677/pdflatex%20%E8%BE%93%E5%87%BA%E4%B8%AD%E7%9A%84%E2%80%9C%E9%A2%97%E7%B2%92%E7%8A%B6%E2%80%9Dtikz%20%E8%8A%82%E7%82%B9%E6%96%87%E6%9C%AC.png)
我正在使用根据以下简单的 tikzfigure 描述生成 PDF 文件pdflatex
。
\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{arrows.meta,backgrounds}
\begin{document}
\begin{tikzpicture}
\foreach \x in {0,...,7} {
\node (n\x0) at (2*\x,0) {Thread \x};
\node (n01) [font=\scriptsize] at (0,-4) {Thread 0,4};
\node (n11) [font=\scriptsize] at (2,-4) {Thread 1,5};
\node (n21) [font=\scriptsize] at (4,-4) {Thread 2,6};
\node (n31) [font=\scriptsize] at (6,-4) {Thread 3,7};
\node (n02) [font=\tiny] at (0,-8) {Thread 0,2,4,6};
\node (n12) [font=\tiny] at (2,-8) {Thread 1,3,5,7};
\node (n03) at (0,-12) {Block};
}
\node (p1) [circle,fill=white] at (0,-2.5) {+};
\node (p2) [circle,fill=white] at (2,-2.5) {+};
\node (p3) [circle,fill=white] at (4,-2.5) {+};
\node (p4) [circle,fill=white] at (6,-2.5) {+};
\node (p5) [circle,fill=white] at (0,-6.5) {+};
\node (p6) [circle,fill=white] at (2,-6.5) {+};
\node (p7) [circle,fill=white] at (0,-10.5) {+};
\begin{scope}[on background layer]
\draw [-{Stealth[scale=1.5]}] (n00.south) -- (p1.north);
\draw [-{Stealth[scale=1.5]}] (n10.south) -- (p2.north);
\draw [-{Stealth[scale=1.5]}] (n20.south) -- (p3.north);
\draw [-{Stealth[scale=1.5]}] (n30.south) -- (p4.north);
\draw [-{Stealth[scale=1.5]}] (n40.south) -- (p1.north);
\draw [-{Stealth[scale=1.5]}] (n50.south) -- (p2.north);
\draw [-{Stealth[scale=1.5]}] (n60.south) -- (p3.north);
\draw [-{Stealth[scale=1.5]}] (n70.south) -- (p4.north);
\draw [-{Stealth[scale=1.5]}] (p1) -- (n01);
\draw [-{Stealth[scale=1.5]}] (p2) -- (n11);
\draw [-{Stealth[scale=1.5]}] (p3) -- (n21);
\draw [-{Stealth[scale=1.5]}] (p4) -- (n31);
\draw [-{Stealth[scale=1.5]}] (n01.south) -- (p5.north);
\draw [-{Stealth[scale=1.5]}] (n11.south) -- (p6.north);
\draw [-{Stealth[scale=1.5]}] (n21.south) -- (p5.north);
\draw [-{Stealth[scale=1.5]}] (n31.south) -- (p6.north);
\draw [-{Stealth[scale=1.5]}] (p5) -- (n02);
\draw [-{Stealth[scale=1.5]}] (p6) -- (n12);
\draw [-{Stealth[scale=1.5]}] (n02.south) -- (p7.north);
\draw [-{Stealth[scale=1.5]}] (n12.south) -- (p7.north);
\draw [-{Stealth[scale=1.5]}] (p7) -- (n03);
\end{scope}
\end{tikzpicture}
\end{document}
该图本身看起来符合预期,唯一令我困扰的是,除第一行之外的每一行中所有节点的标签似乎都没有被正确平滑(这在下面附加的 .png 中可能很难看到,但在原始 PDF 中肯定很明显)。
其他人能重现这个问题吗?是pdflatex
原因还是代码本身有问题?
答案1
问题在于您将相同的文本打印了 8 次。微小的误差都会导致“颗粒状”外观。
为了解决这个问题,请将所有静态元素移出循环。
\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{arrows.meta,backgrounds}
\begin{document}
\begin{tikzpicture}
\foreach \x in {0,...,7} {
\node (n\x0) at (2*\x,0) {Thread \x};
}
\node (n01) [font=\scriptsize] at (0,-4) {Thread 0,4};
\node (n11) [font=\scriptsize] at (2,-4) {Thread 1,5};
\node (n21) [font=\scriptsize] at (4,-4) {Thread 2,6};
\node (n31) [font=\scriptsize] at (6,-4) {Thread 3,7};
\node (n02) [font=\tiny] at (0,-8) {Thread 0,2,4,6};
\node (n12) [font=\tiny] at (2,-8) {Thread 1,3,5,7};
\node (n03) at (0,-12) {Block};
\node (p1) [circle,fill=white] at (0,-2.5) {+};
\node (p2) [circle,fill=white] at (2,-2.5) {+};
\node (p3) [circle,fill=white] at (4,-2.5) {+};
\node (p4) [circle,fill=white] at (6,-2.5) {+};
\node (p5) [circle,fill=white] at (0,-6.5) {+};
\node (p6) [circle,fill=white] at (2,-6.5) {+};
\node (p7) [circle,fill=white] at (0,-10.5) {+};
\begin{scope}[on background layer]
\draw [-{Stealth[scale=1.5]}] (n00.south) -- (p1.north);
\draw [-{Stealth[scale=1.5]}] (n10.south) -- (p2.north);
\draw [-{Stealth[scale=1.5]}] (n20.south) -- (p3.north);
\draw [-{Stealth[scale=1.5]}] (n30.south) -- (p4.north);
\draw [-{Stealth[scale=1.5]}] (n40.south) -- (p1.north);
\draw [-{Stealth[scale=1.5]}] (n50.south) -- (p2.north);
\draw [-{Stealth[scale=1.5]}] (n60.south) -- (p3.north);
\draw [-{Stealth[scale=1.5]}] (n70.south) -- (p4.north);
\draw [-{Stealth[scale=1.5]}] (p1) -- (n01);
\draw [-{Stealth[scale=1.5]}] (p2) -- (n11);
\draw [-{Stealth[scale=1.5]}] (p3) -- (n21);
\draw [-{Stealth[scale=1.5]}] (p4) -- (n31);
\draw [-{Stealth[scale=1.5]}] (n01.south) -- (p5.north);
\draw [-{Stealth[scale=1.5]}] (n11.south) -- (p6.north);
\draw [-{Stealth[scale=1.5]}] (n21.south) -- (p5.north);
\draw [-{Stealth[scale=1.5]}] (n31.south) -- (p6.north);
\draw [-{Stealth[scale=1.5]}] (p5) -- (n02);
\draw [-{Stealth[scale=1.5]}] (p6) -- (n12);
\draw [-{Stealth[scale=1.5]}] (n02.south) -- (p7.north);
\draw [-{Stealth[scale=1.5]}] (n12.south) -- (p7.north);
\draw [-{Stealth[scale=1.5]}] (p7) -- (n03);
\end{scope}
\end{tikzpicture}
\end{document}