5

I want to create a tikz node with two colors (split along a vertical axis) and a single body of text spanning the two parts.

The way I've seen the shapes.multipart library used makes the being confined to a single part of the node, or to write multiple distinct text bodies in the different part whereas I'm looking to share the text.

I could manually do it by creating two nodes at the same coordinates, one containing the text and the other one a multipart node filled in two colors, but if I do it the simple way the dimensions of the multipart node wouldn't adapt to the text size and so the text might overflow from the whole node.

7

There's no need for a multipart node. A regular node can be filled with several colors with path picture command.

\documentclass[tikz,border=2mm]{standalone}

\begin{document}
\begin{tikzpicture}
\node[fill=green!30, path picture={\fill[red!30] (path picture bounding box.west) rectangle (path picture bounding box.north east);}] (a) {This is a node};

\node[fill=green!30, path picture={\fill[red!30] (path picture bounding box.south west) --  (path picture bounding box.north east)-|cycle;}] at (0,-1) {This is a node};

\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.