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.

The title says it all. I have a few nodes, and created a fitting rectangle. Now, I'd like to create another rectangle at exactly the bottom of it, so it would look like one big rectangle has been split in two.

share|improve this question
1  
Unless you provide a complete minimal working example it will be hard to provide an answer to this question. –  N.N. Jun 17 '11 at 11:10
    
You draw another rectangle with the same coordinates but use yshift. Something like: \draw[yshift=-1cm] and then repeat the instructions of the first rectangle. –  Vivi Jun 17 '11 at 11:24
    
@N.N.: In this specific case I don't think a minimal example is mandatory. An image would be much better suited to show what is wanted, but the text is OK so far IMHO. –  Martin Scharrer Jun 17 '11 at 11:30
    
@Vivi: This would only work if the size of the second node is exactly the same, wouldn't it? –  Martin Scharrer Jun 17 '11 at 11:31
    
@Martin Scharrer: you mean the size of the second rectangle? If that's what you mean, correct! I guess an image, as you suggested, would really help :) –  Vivi Jun 17 '11 at 11:37
add comment

3 Answers

up vote 4 down vote accepted

Yes there is also the possibility to use multi-part nodes with rectangle.

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{shapes.multipart} 
\begin{document}

\begin{tikzpicture}[every node/.style={draw, anchor=text, rectangle split, rectangle split parts=2}]
\node {Some text \nodepart{second} more }; 
\end{tikzpicture}
\end{document} 

enter image description here

share|improve this answer
add comment

You can calculate the size of the first rectangle node as follows and use it to draw the second one. One issue is the outer sep of the first node which is normally .5\pgflinewidth, i.e. to place the anchor at the outer edge of the node border, not in the middle of it. This has to be compensated and is error prone if the line width is changed between the nodes.

Note that there is also the possibility to use multi-part nodes. There is one for a circle node, but I'm not sure for rectangle ones.

\documentclass{article}

\usepackage{tikz}
\usetikzlibrary{calc}

\begin{document}
\begin{tikzpicture}
   \node [draw] (A) {Some text};
   \path let \p1 = (A.south west), \p2 = (A.north east) in
    node [draw,minimum width=\x2-\x1-\pgflinewidth,minimum height=\y2-\y1-\pgflinewidth,below right]
        at ([yshift={\pgflinewidth}]A.south west) {more};
\end{tikzpicture}
\end{document}

Result

share|improve this answer
    
Yes, you can split rectangles as well. –  Alan Munn Jun 17 '11 at 12:16
add comment

Given that you're already using the fit library, you can just use that to get your new rectangle. If you're willing to set outer sep=0pt on your original fitting node then you can fit the new rectangle to the old one plus some random coordinate to set the height, or to the southern anchors of the old one. If you're not willing to set the outer sep on the original node, then simply fit the new node to the same nodes as the original one plus an extra one to make it bigger. In the following, I've made the rectangles different colours so it's obvious what is actually being drawn, but if they are the same colour you won't notice that.

\documentclass{article}
% \url{http://tex.stackexchange.com/q/20998/86}
\usepackage{tikz}
\usetikzlibrary{fit}

\begin{document}
\begin{tikzpicture}[inner node/.style={draw,dashed,blue,text=black},outer node/.style={draw,ultra thick}]
\node[inner node] (a) at (0,0) {a};
\node[inner node] (b) at (2,3) {b};
\node[inner node] (c) at (3,2) {c};
\node[fit=(a) (b) (c),outer node,outer sep=0pt,purple] (d) {};
\path (d.south) ++(0,-5) coordinate (e) {};
\node[pink,outer node,inner sep=0pt,fit=(e) (d.south east) (d.south west)] {};
\begin{scope}[xshift=5cm]
\node[inner node] (a) at (0,0) {a};
\node[inner node] (b) at (2,3) {b};
\node[inner node] (c) at (3,2) {c};
\node[fit=(a) (b) (c),outer node,outer sep=0pt,purple] (d) {};
\path (d.south) ++(0,-5) coordinate (e) {};
\node[pink,outer node,inner sep=0pt,fit=(e) (d)] {};
\begin{scope}[xshift=5cm]
\node[inner node] (a) at (0,0) {a};
\node[inner node] (b) at (2,3) {b};
\node[inner node] (c) at (3,2) {c};
\node[fit=(a) (b) (c),outer node,purple] (d) {};
\path (d.south) ++(0,-5) coordinate (e) {};
\node[pink,outer node,fit=(a) (b) (c) (e)] {};
\end{scope}
\end{scope}
\end{tikzpicture}
\end{document}

Result:

fitted rectangles

share|improve this answer
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.