2

I want to do something like that: enter image description here

But I'm having a hard time with the arrow. I was wondering if there was a way to do it without hardcoding every coordinates.

Here is the code of the multipart rectangle:

\documentclass[]{article}
\usepackage{tikz}
\usepackage[skip=2pt]{caption}
\usetikzlibrary{positioning,decorations.pathreplacing, shapes, arrows}
\settowidth{\textwidth}{Multipart rectangles with no line shortening}
\begin{document}

\begin{tikzpicture}[auto, node distance=1cm,
rect/.style={
    rectangle split,
    rectangle split parts=3,
    rectangle split horizontal,
    rectangle split part fill={green!50,green!50,gray!50},
    draw=black,
    rounded corners,
    text width = 3cm
}]

% Split Rectangle
\node[rect] {
    \centerline{ether}
        \nodepart  {two} \centerline{ip}
        \nodepart[text width=5cm]{three}
};

\end{tikzpicture}
\end{document}
2

As described in the manual, section 70.6 Shapes with multiple text parts, there are predefined anchors at the borders between the node parts. If you name your node foo, then foo.two split north is the point where your arrow is pointing to, so you can do

\draw [<-] (foo.two split north) -- +(0,1cm) node[above]{bar};

to get

enter image description here

\documentclass[]{article}
\usepackage{tikz}
\usepackage[skip=2pt]{caption}
\usetikzlibrary{positioning,decorations.pathreplacing, shapes, arrows}
\settowidth{\textwidth}{Multipart rectangles with no line shortening}
\begin{document}

\begin{tikzpicture}[auto, node distance=1cm,
rect/.style={
    rectangle split,
    rectangle split parts=3,
    rectangle split horizontal,
    rectangle split part fill={green!50,green!50,gray!50},
    draw=black,
    rounded corners,
    text width = 3cm,
    align=center % <- alternative to \centerline everywhere
}]

% Split Rectangle
\node[rect] (foo) {
    ether
    \nodepart  {two} ip
    \nodepart[text width=5cm]{three}
};

\draw [<-] (foo.two split north) -- +(0,1cm) node[above]{bar};
\end{tikzpicture}
\end{document}
  • Thanks it's exactly what I wanted! – irevoire Jun 20 at 18:10
  • I'm wondering, if I wanted to put the arrow between ether and ip. How should I do since there is no foo.first ? (also what manual are you talking about ? I searched for tikz manual on google but didn't found anything) – irevoire Jun 20 at 18:31
  • @irevoire That would be foo.text split north. The PGF & TikZ manual is here, see around page 796 (in version 3.1.1). You might be interested in this question too. – frougon Jun 20 at 19:13

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.