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 hope somebody can help me. I am search for a split of a rectangle like this:

\node[rectangle,draw,minimum width=3cm, minimum height=3cm] (rec) {};
\node[name=v1,minimum width=3cm * 0.16cm] at
        ($(rec.north west)!0.5!(rec.west)!0.18!(rec.center)$){$v_1$};
\node[name=v2, minimum width=3cm * 0.16cm] at
    ($(rec.south west)!0.5!(rec.west)!0.18!(rec.center)$){$v_2$};
\draw (rec.north west) rectangle ($(rec.west)!0.32!(rec.center)$) {};
\draw (rec.south west) rectangle ($(rec.west)!0.32!(rec.center)$) {};

But what can I do if I would like to create a rectangle with x variables?

4 variables
+---------+-------------+
|    v1   |             |
+---------+             |
|    d    |             |
+---------+             |
|    c2   |             |
+---------+             |
|    f    |             |
+---------+-------------+

I would like to use a 'for each'-loop and access my rec via north, south, etc. I appreciate any help. Thank you! ;-)

share|improve this question
    
Not sure exactly what you desire, but perhaps Creating a fraction graph in TikZ, or Divide a rectangle into n times k equal cells might help. –  Peter Grill Aug 1 '12 at 22:16

1 Answer 1

A solution using fit, positioning and chains TikZ libraries:

\documentclass{standalone}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage{tikz}
\usetikzlibrary{fit,positioning,chains}
\begin{document}
\begin{tikzpicture}
  \tikzset{
    mybox/.style={
      draw,line width=1pt,align=center,
      text width=1cm,text height=.8em,text depth=.2em,
    },
  }
  \begin{scope}[start chain=going below,node distance=-1pt]
    \foreach \x in {a,v1,d,c2,f,g,h}{
      \node[on chain,mybox](\x){\x};
    }
  \end{scope}
  \coordinate (right) at ([xshift=2cm]a.east);

  \node[fit=(a)(h)(right),inner sep=-.5pt,line width=1pt,draw=blue]
  (rec){};
\end{tikzpicture}
\end{document}

enter image description here

share|improve this answer
    
thank you very much ;-) That's what I'm searching for. –  drh Aug 2 '12 at 20:23

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.