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.

Consider the following example:

\documentclass{article}

\usepackage{tikz}
\usetikzlibrary{calc}

\usepackage{xcolor}

\begin{document}

\def\mydist{1mm}
\begin{tikzpicture}[
        mystyle/.style={
            rectangle,
            rounded corners,
            draw=black, 
            very thick,
            text width=2cm,
        }
    ]
    \node [mystyle] (A) {A\\text\\text\\text};
    \node [mystyle, anchor=north] (B) at ($(A.south) - (0,\mydist)$) {B\\text\\text};
    \node [mystyle, anchor=south west] (C) at ($(B.south east) + (\mydist,0)$) {C\\text};

    % here is the problem
    \node [mystyle, anchor=south, red] (D) at ($(C.north)  + (0,\mydist)$) {D\\???};
\end{tikzpicture}

\end{document}

How can I calculate the minimum height for node D so that the upper edges of the nodes A and D are aligned?

Or should I use a different approach?

share|improve this question
    
This is very similar to Fit only the height on a node. Also check out the positioning library which makes placing nodes relative to each other very easy. –  Qrrbrbirlbel Apr 9 '13 at 18:32
add comment

1 Answer

up vote 3 down vote accepted

Here's one possibility, using the let syntax; the node's text depth is used to give the right size:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{positioning,calc}
\usepackage{xcolor}

\begin{document}

\begin{tikzpicture}[
        mystyle/.style={
            rectangle,
            rounded corners,
            draw=black, 
            line width=1pt,
            text width=2cm,
        },
  node distance=2mm
    ]
\node [mystyle] (A) {A\\text\\text\\text\\text};
\node [mystyle,below=of A] (B) {B\\text\\text};
\node [mystyle, right=of B.south east,anchor=south west] (C) {C\\text};
\path let \p1=([yshift=2mm]C.north), \p2=(A.north) in
  node [mystyle, anchor=south,red,text depth={\y2-\y1-\pgflinewidth-1.1\baselineskip},above=of C] 
  (D) {A\\B\\C\\D};
\end{tikzpicture}

\end{document}

enter image description here

Not related to the problem, but I used node distance (this saves the definition of a new length) and the features provided by the positioning library to position the nodes.

share|improve this answer
    
Many thanks for your answer. –  sergej Apr 10 '13 at 10:54
    
@sergej please see my updated answer. –  Gonzalo Medina Apr 10 '13 at 13:54
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.