为什么蓝线和红线与黑线不吻合,并且相互重叠?
\documentclass[tikz,margin=5pt]{standalone}
\usetikzlibrary{calc}
\usetikzlibrary{decorations.markings}
\begin{document}
\begin{tikzpicture}[Dble/.style args={#1 and #2}{%
decoration={%
markings,% switch on markings
mark=at position 0 with {%
\node[yshift= .5\pgflinewidth] (Axx) {};
\node[yshift=-.5\pgflinewidth] (Bxx) {};},
mark=at position 1 with {%
\node[yshift= .5\pgflinewidth] (Ayy) {};
\node[yshift=-.5\pgflinewidth] (Byy) {};
\draw [#1] (Axx)--(Ayy) ;
\draw [#2] (Bxx)--(Byy) ;}
},
postaction={decorate}}
]
\coordinate (A) at (0,0) ;
\coordinate (B) at (1,1) ;
\draw[Dble={blue and red},very thick] (A)--(B) ;
\end{tikzpicture}
\end{document}
答案1
\documentclass[tikz,margin=5pt]{standalone}
\usetikzlibrary{calc}
\usetikzlibrary{decorations.markings}
\begin{document}
\begin{tikzpicture}[Dble/.style args={#1 and #2}{%
decoration={%
markings,% switch on markings
mark=at position 0 with {%
\coordinate (Axx) at (0,.5\pgflinewidth);%
\coordinate (Bxx) at (0,-.5\pgflinewidth);},%
mark=at position 1 with {%
\coordinate (Ayy) at (0,.5\pgflinewidth);%
\coordinate (Byy) at (0,-.5\pgflinewidth);%
\draw [#1] (Axx)--(Ayy) ;%
\draw [#2] (Bxx)--(Byy) ;}%
},%
postaction={decorate}}
]
\coordinate (A) at (0,0) node {A};
\coordinate (B) at (1,1) ;
\path[Dble={blue and red},very thick] (A)--(B) ;
\end{tikzpicture}
\end{document}