对我来说,以下 MWE 应该有效:
\documentclass[a4paper,11pt]{article}
\usepackage{xunicode}% for XeTex!
\usepackage{fontspec}% for XeTex!
\usepackage{xltxtra} % for XeTex!
\usepackage[french]{babel}
\usepackage{tikz}
\usetikzlibrary{positioning}
\defaultfontfeatures{Scale=MatchLowercase}
\setromanfont[Mapping=tex−text]{Linux Libertine O}
\setsansfont [Mapping=tex−text]{Linux Biolinum O}
\setmonofont [Mapping=tex−text]{Inconsolata}
\begin{document}
\begin{figure}[ht]
\centering
\begin{tikzpicture}
[note/.style={draw,black,circle,inner sep=2mm},
label distance=-1mm,label position=below left,
double distance=.5mm]
\node[note,double] (C) [label=Do ] {};
\node[note,left=of C] (F) [label=Fa ] {};
\node[note,right=of C] (G) [label=Sol ] {};
\node[note,right=of G] (D) [label=Ré ] {};
\node[note,above=of F] (A) [label=La ] {};
\node[note,right=of A] (E) [label=Mi ] {};
\node[note,right=of E] (B) [label=Si ] {};
\node[note,right=of B] (Fd) [label= Fa♯] {};
\node[note,above=of A] (Cd) [label= Do♯] {};
\node[note,right=of Cd] (Gd) [label=Sol♯] {};
\node[note,right=of Gd] (Dd) [label= Ré♯] {};
\node[note,right=of Dd] (Ad) [label= La♯] {};
%\draw (F) -- (C) -- (G) -- (D);
%\draw (A) -- (E) -- (B) -- (Fd);
%\draw (Cd) -- (Gd) -- (Dd) -- (Ad);
%
%\draw (F) -- (A) -- (Cd);
%\draw (C) -- (E) -- (Gd);
%\draw (G) -- (B) -- (Dd);
%\draw (D) -- (Fd) -- (Ad);
\begin{scope}[fill=black!50]
\filldraw (C) -- (E) -- (G) -- cycle; % DOM
\filldraw (A) -- (Cd) -- (E) -- cycle; % LAm
\end{scope}
\draw[dashed] (Cd.north) -- +(0cm ,6mm );
\draw[dashed] (Gd.north) -- +(0cm ,6mm );
\draw[dashed] (Dd.north) -- +(0cm ,6mm );
\draw[dashed] (Ad.north) -- +(0cm ,6mm );
\draw[dashed] (F.south) -- +(0cm ,-6mm);
\draw[dashed] (C.south) -- +(0cm ,-6mm);
\draw[dashed] (G.south) -- +(0cm ,-6mm);
\draw[dashed] (D.south) -- +(0cm ,-6mm);
\draw[dashed] (F.west) -- +(-6mm,0cm );
\draw[dashed] (A.west) -- +(-6mm,0cm );
\draw[dashed] (Cd.west) -- +(-6mm,0cm );
\draw[dashed] (Ad.east) -- +(6mm ,0cm );
\draw[dashed] (Fd.east) -- +(6mm ,0cm );
\draw[dashed] (D.east) -- +(6mm ,0cm );
\end{tikzpicture}
\end{figure}
\end{document}
但我没有得到想要的结果,即 2 个填充的三角形black!50
。相反,我得到了这个:
有什么原因吗?你得到的结果是一样的吗?
答案1
\documentclass[a4paper,11pt]{article}
\usepackage{xunicode}% for XeTex!
\usepackage{fontspec}% for XeTex!
\usepackage{xltxtra} % for XeTex!
\usepackage[french]{babel}
\usepackage{tikz}
\usetikzlibrary{positioning}
\defaultfontfeatures{Scale=MatchLowercase}
\setromanfont[Mapping=tex−text]{Linux Libertine O}
\setsansfont [Mapping=tex−text]{Linux Biolinum O}
\setmonofont [Mapping=tex−text]{Inconsolata}
\begin{document}
\begin{figure}[ht]
\centering
\begin{tikzpicture}
[note/.style={draw,black,circle,inner sep=2mm},
label distance=-1mm,label position=below left,
double distance=.5mm]
\node[note,double] (C) [label=Do ] {};
\node[note,left=of C] (F) [label=Fa ] {};
\node[note,right=of C] (G) [label=Sol ] {};
\node[note,right=of G] (D) [label=Ré ] {};
\node[note,above=of F] (A) [label=La ] {};
\node[note,right=of A] (E) [label=Mi ] {};
\node[note,right=of E] (B) [label=Si ] {};
\node[note,right=of B] (Fd) [label= Fa♯] {};
\node[note,above=of A] (Cd) [label= Do♯] {};
\node[note,right=of Cd] (Gd) [label=Sol♯] {};
\node[note,right=of Gd] (Dd) [label= Ré♯] {};
\node[note,right=of Dd] (Ad) [label= La♯] {};
%\draw (F) -- (C) -- (G) -- (D);
%\draw (A) -- (E) -- (B) -- (Fd);
%\draw (Cd) -- (Gd) -- (Dd) -- (Ad);
%
%\draw (F) -- (A) -- (Cd);
%\draw (C) -- (E) -- (Gd);
%\draw (G) -- (B) -- (Dd);
%\draw (D) -- (Fd) -- (Ad);
\begin{scope}[fill=black!50]
\filldraw[opacity=.5] (C.center) -- (E.center) -- (G.center) -- cycle; % DOM
\filldraw[opacity=.5] (A.center) -- (Cd.center) -- (E.center) -- cycle; % LAm
\end{scope}
\draw[dashed] (Cd.north) -- +(0cm ,6mm );
\draw[dashed] (Gd.north) -- +(0cm ,6mm );
\draw[dashed] (Dd.north) -- +(0cm ,6mm );
\draw[dashed] (Ad.north) -- +(0cm ,6mm );
\draw[dashed] (F.south) -- +(0cm ,-6mm);
\draw[dashed] (C.south) -- +(0cm ,-6mm);
\draw[dashed] (G.south) -- +(0cm ,-6mm);
\draw[dashed] (D.south) -- +(0cm ,-6mm);
\draw[dashed] (F.west) -- +(-6mm,0cm );
\draw[dashed] (A.west) -- +(-6mm,0cm );
\draw[dashed] (Cd.west) -- +(-6mm,0cm );
\draw[dashed] (Ad.east) -- +(6mm ,0cm );
\draw[dashed] (Fd.east) -- +(6mm ,0cm );
\draw[dashed] (D.east) -- +(6mm ,0cm );
\end{tikzpicture}
\end{figure}
\end{document}
答案2
这个问题经常出现,所以可能需要一点解释。当在开放路径上发出填充命令时,TikZ 会自动将路径的最后一个接收点与路径的第一个点连接起来并填充该区域(就像--cycle;
放置了一样)。所以
\begin{tikzpicture}
\filldraw[fill=blue!10, draw=red,thick] (0,0) -- (1,1) -- (1,0);
\end{tikzpicture}
给出
当我们fill
在一条线上使用时,它仍然会关闭路径,但结果又是一条线,因此我们看不到有关填充的任何内容。
\begin{tikzpicture}
\filldraw[fill=blue!10, draw=red,thick] (0,0) -- (1,1) -- (1,0);
\end{tikzpicture}
现在,当我们连接节点形状时,TikZ 会启动一个稍微复杂的边框形状计算机制,它只连接两个节点边框上的共线点,换句话说,它不使用节点坐标,而是计算边框位置
\begin{tikzpicture}
\node[circle,draw] (a) at (0,0) {a};
\node[draw] (b) at (1,2) {b};
\draw[draw=red,thick] (0,0) -- (1,2) ;
\draw[draw=blue,ultra thick] (a) -- (b) ;
\end{tikzpicture}
因此继续沿着这条路径到达另一个节点,我们可以得到:
\begin{tikzpicture}
\node[circle,draw] (a) at (0,0) {a};
\node[draw] (b) at (1,2) {b};
\node[draw] (c) at (2,0) {c};
\draw[draw=red,thick] (0,0) -- (1,2) -- (2,0);
\draw[draw=blue,ultra thick] (a) -- (b) --(c);
\end{tikzpicture}
因此,如果我们使用节点作为坐标,我们会得到两条不相交的线,但当我们使用坐标时,我们会得到一条连续的路径。因此,当在这些路径上发出填充时,第一个会创建两条明显不可见的填充线,但第二个会按预期运行。
\begin{tikzpicture}
\node[circle,draw] (a) at (0,0) {a};
\node[draw] (b) at (1,2) {b};
\node[draw] (c) at (2,0) {c};
\draw[fill=blue!10,draw=red,thick] (0,0) -- (1,2) -- (2,0);
\draw[fill=black!10,draw=blue,ultra thick] (a) -- (b) --(c);
\end{tikzpicture}
这就是为什么使用(node.center)
有效但(node)
不起作用,因为锚点也是固定坐标,而节点形状通常不是(除非节点是\coordinate
具有点的节点形状。)