TikZ - 为什么网格的外线比网格本身更亮?

TikZ - 为什么网格的外线比网格本身更亮?

为什么三角网格的外线(=深灰色)看起来更亮?当我更改为时,它似乎会获得相同的颜色draw=graydraw=black但这对我来说没有多大意义(目前)。有人可以解释一下吗?

带有 draw=gray 的图片

在此处输入图片描述

带有 draw=black 的图片

在此处输入图片描述

平均能量损失

\documentclass[
11pt
]{scrartcl}

\usepackage{
tikz,
relsize,
amsmath
}

\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{lmodern}


%% from here on forth TikZ-stuff

\usetikzlibrary{
calc,trees,shadows,positioning,arrows,chains,shapes.geometric,
decorations.pathreplacing,decorations.pathmorphing,shapes,
matrix,shapes.symbols,patterns,intersections,fit
}

\pgfdeclarelayer{background layer}
\pgfdeclarelayer{foreground layer}
\pgfsetlayers{background layer,main,foreground layer}

\tikzset{
>=latex
}

\begin{document}
\begin{center}
\begin{tikzpicture}[font=\sffamily\small]
%N
\draw[style=help lines,step=0.5cm] (0,0) grid (9,6);
%
\draw[->,thick] (-0.1,0) -- (9.5,0) node[anchor=west]{Input};
\draw[->,thick] (0,-0.1) -- (0,6.5) node[anchor=south]{Output}; 
%
\foreach \x in {0,1,...,9} \draw [thick](\x cm,-2pt) -- (\x cm,2pt);
\foreach \y in {0,1,...,6} \draw [thick](-2pt,\y) -- (2pt,\y);
%
\foreach \x in {0,1,...,9} \draw (\x cm, 0 cm) node[anchor=north]{\x};
\foreach \y in {0,1,...,6}  \draw (0 cm, \y cm) node[anchor=east]{\y};
\draw
(2,1) coordinate (A)
(3,3) coordinate (B)
(3,2) coordinate (C)
(4,3) coordinate (D)
(5,4) coordinate (E)
(5,2) coordinate (F)
(6,3) coordinate (G)
(8,5) coordinate (H)
;
%%Cone
\begin{pgfonlayer}{background layer}
\draw[draw=gray,fill=gray,pattern=grid,draw opacity=0.6,fill opacity=0.6] (F) -- ($(F) + (-3.5,0)$) -- ($(F) + (0,3.5)$) -- cycle;
\end{pgfonlayer}
%%Labels + Circles
\foreach \pt/\labpos in {A/below right,B/below right,C/below right,D/below right,E/below right,F/below right,G/below right,H/below right}{
        \filldraw (\pt) circle(2pt) node[\labpos=3pt,fill=white]{\pt};
}
\end{tikzpicture}
\end{center}

\end{document}

答案1

不设置draw opacity=0.6:这会使黑线显示为灰色,而灰线显示为较浅的灰色,因为白纸透过了。颜色draw未应用于网格图案,其颜色仍为黑色,这就是为什么它显示为比轮廓更深的灰色。

为了使网格和轮廓都具有相同的灰色,只需设置draw=gray, pattern color=gray(不带draw opacity=0.6):

\documentclass[
11pt
]{standalone}

\usepackage{
tikz,
amsmath
}

\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{lmodern}


%% from here on forth TikZ-stuff

\usetikzlibrary{
calc,trees,shadows,positioning,arrows,chains,shapes.geometric,
decorations.pathreplacing,decorations.pathmorphing,shapes,
matrix,shapes.symbols,patterns,intersections,fit
}

\pgfdeclarelayer{background layer}
\pgfdeclarelayer{foreground layer}
\pgfsetlayers{background layer,main,foreground layer}

\tikzset{
>=latex
}

\begin{document}
\begin{tikzpicture}[font=\sffamily\small]
%N
\draw[style=help lines,step=0.5cm] (0,0) grid (9,6);
%
\draw[->,thick] (-0.1,0) -- (9.5,0) node[anchor=west]{Input};
\draw[->,thick] (0,-0.1) -- (0,6.5) node[anchor=south]{Output}; 
%
\foreach \x in {0,1,...,9} \draw [thick](\x cm,-2pt) -- (\x cm,2pt);
\foreach \y in {0,1,...,6} \draw [thick](-2pt,\y) -- (2pt,\y);
%
\foreach \x in {0,1,...,9} \draw (\x cm, 0 cm) node[anchor=north]{\x};
\foreach \y in {0,1,...,6}  \draw (0 cm, \y cm) node[anchor=east]{\y};
\draw
(2,1) coordinate (A)
(3,3) coordinate (B)
(3,2) coordinate (C)
(4,3) coordinate (D)
(5,4) coordinate (E)
(5,2) coordinate (F)
(6,3) coordinate (G)
(8,5) coordinate (H)
;
%%Cone
\begin{pgfonlayer}{background layer}
\draw[draw=gray,fill=gray,pattern=grid,pattern color=gray] (F) -- ($(F) + (-3.5,0)$) -- ($(F) + (0,3.5)$) -- cycle;
\end{pgfonlayer}
%%Labels + Circles
\foreach \pt/\labpos in {A/below right,B/below right,C/below right,D/below right,E/below right,F/below right,G/below right,H/below right}{
        \filldraw (\pt) circle(2pt) node[\labpos=3pt,fill=white]{\pt};
}
\end{tikzpicture}

\end{document}

相关内容