我无法使用 获得两个相邻节点形状之间的单边框tikz
。当我使用thick
边框时,它会导致两个节点连接处出现重叠的双边框。
如何避免这种情况?
我目前尝试使用定位库以及链库。
我使用以下代码生成它。
\documentclass{standalone} % standalone
\usepackage{graphicx}
\usepackage[usenames,dvipsnames,svgnames,table]{xcolor}
\usepackage{tikz}
\usetikzlibrary{chains,shapes,positioning}
\begin{document}
\tikzstyle{b1} = [rectangle,
fill = red!50,
draw = black, thick,
fill opacity = 0.5, text opacity = 1]
\tikzstyle{b2} = [rectangle,
fill = blue!50,
draw = black, thick,
fill opacity = 0.5, text opacity = 1]
\begin{tikzpicture}[auto,node distance=1cm and 0cm,every node/.style={font=\small}]
\node(A)[b1] at (0,0) {A};
\node(B)[b2,right=of A]{B};
\end{tikzpicture}
\begin{tikzpicture}[start chain,node distance=0mm,every node/.style={font=\small}]
\node[on chain,b1] {A};
\node[on chain,b2] {B};
\end{tikzpicture}
\end{document}
答案1
我将扩展我的评论来回答:
\documentclass[border=3mm]{standalone} % standalone
\usepackage{tikz}
\usetikzlibrary{chains,shapes,positioning}
\tikzset{
every node/.style = {rectangle, draw=black, thick,
fill opacity = 0.5, text opacity = 1,
font=\small,
outer sep=0pt,% <-- this eliminate your problem
},
b1/.style = {fill=red!50},
b2/.style = {fill=blue!50}
}
\begin{document}
\begin{tikzpicture}[auto,node distance=1cm and 0cm]
\node(A)[b1] {A};
\node(B)[b2,right=of A]{B};
\end{tikzpicture}
\begin{tikzpicture}[start chain=going right,node distance=0mm]
\node[on chain,b1] {A};
\node[on chain,b2] {B};
\end{tikzpicture}
\end{document}
上述代码(基于稍微缩短的 MWE)生成: