Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I'm wondering, is it possible to customize the splitting line when defining a node which has multiple text parts? For instance, instead of a solid line, I would like it to be dotted or dashed.

For instance, the code below generates the following picture:

enter image description here

\documentclass{standalone}

\usepackage{tikz}
\usetikzlibrary{shapes}
\usetikzlibrary{arrows}
\usetikzlibrary{positioning}

\begin{document}
\begin{tikzpicture}
  \node[rectangle split, draw] {1 \nodepart{two} 2 \nodepart{three} 3 \nodepart{four} 4};
\end{tikzpicture}
\end{document}

What I would like is the line between 1-2, 2-3, and 3-4 to be something else than just a solid black line.

share|improve this question
    
We've had something fairly similar before, not sure if it's an actual duplicate but it might give you (or someone) a place to start: tex.stackexchange.com/q/15577/86 –  Andrew Stacey Nov 10 '11 at 14:42
    
@AndrewStacey: Yeah, I saw that question also but it only deals with removing the line, not augmenting it. –  gablin Nov 10 '11 at 16:00
add comment

1 Answer

up vote 4 down vote accepted

There is no option to do that. But: there are good news. You can disable the separator lines between the 'sub-nodes' (with the option rectangle split draw splits=false - as you see it takes a boolean argument) and manually draw the separators, as you wish. This is possible since the anchors for the end-points of the separator lines are still available and freely accessible. All you need to do is name your node. (Here I gave it the very original examplenode name.):

\documentclass{standalone}

\usepackage{tikz}
\usetikzlibrary{shapes}
\usetikzlibrary{arrows}
\usetikzlibrary{positioning}

\begin{document}
\begin{tikzpicture}
  \node[name=examplenode, rectangle split, rectangle split draw splits=false, draw] {1 \nodepart{two} 2 \nodepart{three} 3 \nodepart{four} 4};
  \draw[dashed] (examplenode.text split west) -- (examplenode.text split east);
  \draw[dashed] (examplenode.two split west) -- (examplenode.two split east);
  \draw[dashed] (examplenode.three split west) -- (examplenode.three split east);
\end{tikzpicture}
\end{document}

enter image description here

EDIT: In case of horizontal split rectangles the names of the anchors are not 'translated'. In this case a small hack, involving the use of the calc library for TikZ is necessary:

\documentclass{standalone}

\usepackage{tikz}
\usetikzlibrary{shapes}
\usetikzlibrary{arrows}
\usetikzlibrary{calc,positioning}

\begin{document}
\begin{tikzpicture}
  \node[name=examplenode, rectangle split, rectangle split horizontal, rectangle split draw splits=false, draw] {1 \nodepart{two} 2 \nodepart{three} 3 \nodepart{four} 4};
  \draw[dashed] ($(examplenode.north)!0.5!(examplenode.north west)$) -- ($(examplenode.south)!0.5!(examplenode.south west)$);
  \draw[dashed] (examplenode.north) -- (examplenode.south);
  \draw[dashed] ($(examplenode.north)!0.5!(examplenode.north east)$) -- ($(examplenode.south)!0.5!(examplenode.south east)$);
\end{tikzpicture}
\end{document}

Here, the corners of the rectangle are still named the same way and so are the centers of the top and bottom lines. By taking the middle of the top and bottom line (examplenode.north, examplenode.south) you can draw the centerline. the other two lines are used by finding the middle of the segments between corner and middle of top/bottom line. (This latter code can be adapted to position the lines separating the subnodes in different places e.g. when the subnodes are not identical in size.) Below a more generalized code, using \foreach loops to draw the separator lines.

\documentclass{standalone}

\usepackage{tikz}
\usetikzlibrary{shapes}
\usetikzlibrary{arrows}
\usetikzlibrary{calc,positioning}

\begin{document}
\begin{tikzpicture}
  \node[name=examplenode, rectangle split, rectangle split horizontal, rectangle split draw splits=false, draw] {1 \nodepart{two} 2 \nodepart{three} 3 \nodepart{four} 4};
  \foreach \subnode in {1,...,3}% counter goes 1 to number_of_subnodes-1
  {\draw[dashed] ($(examplenode.north east)!{\subnode*0.25}!(examplenode.north west)$) -- ($(examplenode.south east)!{\subnode*0.25}!(examplenode.south west)$);}
\end{tikzpicture}
\end{document}

enter image description here

If you substitute in the above code the anchors (change the line in the \foreach loop to: {\draw[dashed] ($(examplenode.north east)!{\subnode*0.25}!(examplenode.south east)$) -- ($(examplenode.north west)!{\subnode*0.25}!(examplenode.south west)$);}, you will have the vertical node split properly.

share|improve this answer
    
That's cool! But what if the text parts are empty? I can't seem to get that working... –  gablin Nov 10 '11 at 16:11
    
@gablin: It should work, though. I can compile it without any problems and get the proper result. I used {\nodepart{two}\nodepart{three}\nodepart{four}} and it worked perfectly. Maybe you can give more details about the problem you experience? –  Count Zero Nov 10 '11 at 16:18
    
The problem appears to be that I'm attempting to use this one a multi-part node in horizontal mode, and then it says that "text is an unknown function". –  gablin Nov 11 '11 at 9:12
    
I understand... The rectangle split thingy does not have the same anchors in horizontal mode. A more elaborate hack necessary - see my edit to the answer. –  Count Zero Nov 11 '11 at 17:22
    
Ah perfect! Thanks a bunch! –  gablin Nov 12 '11 at 15:05
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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