我想要一些水平相邻的矩形节点。
我的尝试是可以的,但不幸的是它将边缘的外部彼此相邻放置,因此矩形之间的边框看起来厚度是原来的两倍。
我希望边的中点彼此相邻。 有办法吗?
这是我的示例代码:
\documentclass[border=6mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{calc}
\begin{document}
\begin{tikzpicture}[
box/.style={minimum height=0.5cm, draw=black, inner sep=0, thick}
]
\foreach \k in {0,...,7}
{
\coordinate (a) at (\k*3cm,0);
\pgfmathsetmacro\wa{1.8cm+0.4cm*cos(\k*60)}
\pgfmathsetmacro\wb{0.2cm+0.05cm*cos(\k*47)}
\node[fill=red!50!white, minimum width=\wa, box, anchor=west] (boxa) at (a) {};
\node[fill={rgb:green,1;white,1;black,1}, minimum width=\wb, box, anchor=west] (boxb) at (boxa.east) {};
}
\end{tikzpicture}
\end{document}
答案1
抱歉,我看错了问题。只需按 向后移动即可-\pgflinewidth
。
\documentclass[border=6mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{calc}
\begin{document}
\begin{tikzpicture}[
box/.style={minimum height=0.5cm, draw=black, inner sep=0, thick}
]
\foreach \k in {0,...,7}
{
\coordinate (a) at (\k*3cm,0);
\pgfmathsetmacro\wa{1.8cm+0.4cm*cos(\k*60)}
\pgfmathsetmacro\wb{0.2cm+0.05cm*cos(\k*47)}
\node[fill=red!50!white, minimum width=\wa, box, anchor=west] (boxa) at (a) {};
\node[fill={rgb:green,1;white,1;black,1}, minimum width=\wb, box,
anchor=west] (boxb) at ([xshift=-\pgflinewidth]boxa.east) {};
}
\end{tikzpicture}
\end{document}