在撰写论文时,我尝试用灰色显示部分排序的各个区域。理想情况下,为了解释清楚,我想用垂直条纹将某些区域变灰,如下所示:
我知道如何构造图形/偏序集图像,但不知道如何构造条纹区域。有人能给我指点一下吗?
编辑。感谢这些建议,我能够做到以下几点:
\documentclass[tikz]{standalone}
\usepackage{tikz}
\usetikzlibrary{patterns, arrows}
\pgfdeclarepatternformonly{super ultra thick north east lines}{\pgfqpoint{-2pt}{-2pt}}{\pgfqpoint{10pt}{10pt}}{\pgfqpoint{10pt}{10pt}}%
{
\pgfsetlinewidth{2pt}
\pgfpathmoveto{\pgfqpoint{-1pt}{-1pt}}
\pgfpathlineto{\pgfqpoint{9pt}{9pt}}
\pgfusepath{stroke}
}
\begin{document}
\tikzset{
pon/.style = {circle,align=center, black, draw=black, text width=3.0em, thick},
}
\begin{tikzpicture}[->,level/.style={sibling distance = 2.5cm/#1, level distance = 1.5cm}, style={very thick}]
\node (max) [pon] at (0,4) {$c_1, c_2, c_3\ $};
\node (c1c2) [pon] at (-2, 2) {$c_1, c_2$};
\node (c1c3) [pon] at (0, 2) {$c_1, c_3$};
\node (c2c3) [pon] at (2, 2) {$c_2, c_3$};
\node (c1) [pon] at (-2, 0) {$c_1$};
\node (c2) [pon] at (0, 0) {$c_2$};
\node (c3) [pon] at (2, 0) {$c_3$};
\draw (max) -- (c1c2);
\draw (max) -- (c1c3);
\draw (max) -- (c2c3);
\draw (c1c2) -- (c1);
\draw (c1c2) -- (c2);
\draw (c1c3) -- (c1);
\draw (c1c3) -- (c3);
\draw (c2c3) -- (c2);
\draw (c2c3) -- (c3);
% top row shading
\path (-2.75,4.75) rectangle (3,3) [path picture={
\foreach \xShift in {-50,-40,...,160}
\draw[line width=2pt, opacity=.5, shorten <=-2\pgflinewidth] ([xshift=\xShift pt] path picture bounding box.south west)
-- ++ (100pt,100pt);
}];
% bottom
\path (-2.75,-1) rectangle (3,1) [path picture={
\foreach \xShift in {-50,-40,...,160}
\draw[line width=2pt, opacity=.5, shorten <=-2\pgflinewidth] ([xshift=\xShift pt] path picture bounding box.south west)
-- ++ (100pt,100pt);
}];
\end{tikzpicture}
\end{document}
答案1
第一个例子使用已经定义的模式north east lines
,该模式使用默认线宽.4pt
(thin
)并且线之间有固定的间距。
第二个示例使用类似的super ultra thick north east lines
线宽定义2pt
,同时使用更多线间距。结合使用,opacity
这可能会产生不美观的结果,因为这些线是由许多短线构成的。根据查看器的不同,我看到了不同的渲染效果。
第三个示例使用与 ingpath picture
类似的工作方式,fill
因为它会根据路径本身进行裁剪。您还可以更好地控制线条,因为它们可以相对于路径进行定位。如果您的路径较高或较宽,则可能需要根据您的路径调整值。
代码
\documentclass[tikz]{standalone}
\usetikzlibrary{patterns}
\pgfdeclarepatternformonly{super ultra thick north east lines}{\pgfqpoint{-2pt}{-2pt}}{\pgfqpoint{10pt}{10pt}}{\pgfqpoint{10pt}{10pt}}%
{
\pgfsetlinewidth{2pt}
\pgfpathmoveto{\pgfqpoint{-1pt}{-1pt}}
\pgfpathlineto{\pgfqpoint{9pt}{9pt}}
\pgfusepath{stroke}
}
\begin{document}
\tikz\pattern[opacity=.5, pattern=north east lines] (0,0) rectangle (3,2);
\tikz\pattern[opacity=.5, pattern=super ultra thick north east lines] (0,0) rectangle (3,2);
\tikz
\path (0,0) rectangle (3,2) [path picture={
\foreach \xShift in {-50,-40,...,100}
\draw[line width=2pt, opacity=.5, shorten <=-2\pgflinewidth] ([xshift=\xShift pt] path picture bounding box.south west)
-- ++ (100pt,100pt);
}];
\end{document}