2

I want to have some rectangle nodes horizontally adjacent to each other.

My attempt at this is ok, but unfortunately it places the outer part of the edges adjacent to each other, so the border between rectangles looks twice as thick.

enter image description here

I would like the midpoint of the edges to be adjacent to each other. Is there a way to do this?

Here is my sample code:

\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}
2

Sorry, misread the question. Just shift back by -\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}

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.