我需要为我的矩形节点获取不同颜色的边缘。
我发现这个问题 如何仅设置 tikz 节点的边框颜色的一侧?
答案中提到的 \tikzset 有输入参数,我不知道在与 \node 一起使用时如何设置它们。
我试图删除参数并设置样式,但我得到的只是一个无限循环的 xetex。
\documentclass{article}
\usepackage{tikz}
\usepackage{pgfplots}
\tikzset{%
mynode/.style ={
\draw[thick,red,line cap=butt,shorten <= -0.5\pgflinewidth,shorten >= 0.5\pgflinewidth] (a.south west) |- (a.north east);
\draw[thick,blue,line cap=butt,shorten <= 0.5\pgflinewidth,shorten >= -0.5\pgflinewidth] (a.south west) -| (a.north east);
}
}
\begin{document}
\begin{figure}[ht]
\begin{center}
\begin{tikzpicture}
\tikzstyle{main}=[rectangle, minimum width = 30mm,minimum height = 50mm, thick, draw =black!80, node distance = 6mm]
\node[main] (m) {$A$ };
\node[mynode] [right=of m] (x2) { $R$}; %commenting this line out with eliminate the infinite loop
\end{tikzpicture}
\end{center}
\end{figure}
\end{document}
提前致谢
答案1
如果你正在寻找这样的东西
以下 MWE 可能会有所帮助:
\documentclass[tikz,border=3mm]{standalone}
\newcommand\ppbb{path picture bounding box}
\tikzset{%
mynode/.style = {rectangle,
path picture={%
\draw[thick,red] (\ppbb.south west) |- (\ppbb.north east);
\draw[thick,blue] (\ppbb.south west) -| (\ppbb.north east);
},% end of path picture
},
}% end of tikzset
\begin{document}
\begin{tikzpicture}
\node (x2) [mynode] {$R$};
\end{tikzpicture}
\end{document}
编辑: 或外观略有不同
使用以下代码(略作修改)获得:
\documentclass[tikz,border=3mm]{standalone}
\newcommand\ppbb{path picture bounding box}
\tikzset{%
myline/.style={draw=#1, thick, shorten <=0.5\pgflinewidth},
mynode/.style = {rectangle,
path picture={%
\draw[myline=red] (\ppbb.south west) |- (\ppbb.north east);
\draw[myline=blue] (\ppbb.north east) |- (\ppbb.south west);
},% end of path picture
},
}% end of tikzset
\begin{document}
\begin{tikzpicture}
\node (x2) [mynode] {$R$};
\end{tikzpicture}
\end{document}