2

I have the following tikz picture:

\documentclass{article}
\usepackage{tikz}
\usepackage{color}
\usetikzlibrary{matrix}
\usetikzlibrary{decorations.pathreplacing}


\begin{document}

  \begin{tikzpicture}

    \begin{scope}[xshift=-3.5cm,yshift=0cm,scale=1]
      \draw [draw=black, line width=0.35mm, fill=red] (0,0) -- (0,1.5) -- (2.5,1.5) -- (2.5, 0) node[midway,above] {} -- (0,0) node[midway,right] {};
      \node at (0.75,1.5) {};
    \end{scope}

    \begin{scope}[xshift=-3.5cm,yshift=0cm,scale=1]
      \draw [draw=black, line width=0.35mm, fill=red] (2.7,0) -- (2.7,1.5) -- (5.2,1.5) -- (5.2, 0) node[midway,above] {} -- (0,0) node[midway,left] {};
      \node at (0.75,1.5) {};
    \end{scope}

  \end{tikzpicture}

\end{document}
  1. I would like to add some writing above the rectangles, but using the available nodes there (with {}) places the text where I wouldn't expect. (especially for midway,above).

  2. I would like to have a writing in the middle of the rectangle.

  3. There is a strange line connecting the two rectangles, and I am not sure what is its source (at the bottom). Is there a way to remove it?

1

Try:

\documentclass{article}
\usepackage{tikz}
\usepackage{color}
\usetikzlibrary{decorations.pathreplacing, matrix, positioning}

\begin{document} 
\begin{tikzpicture}[
  node distance = 3mm,
box/.style = {% definition of rectangle as node
    draw, line width=0.35mm, fill=red,
  text width=23mm, minimum height=15mm, align=center,
  inner sep=1mm, outer sep=0pt}
                    ]
\node (box1) [box, label=above:label 1] {text 1};
\node (box2) [box, right=of box1,
              label=above:label 2]   {text 2};
\end{tikzpicture}
\end{document}

enter image description here

As you can see, I take very different approach in drawing your rectangles. The scope is not intended for positioning single element of picture. For this I use TikZ library positioning, and set distance between nodes to 3mm. Since rectangles are drawn by nodes, you can easy add text in them as well ad labels.

Property of "rectangles", i.e. nodes, are defined with style box, where is determined it width, height, text position, fill etc.

It is true, that TikZ manual is huge, however, it is very worth to read thir part: TikZ is kein Ziechenprogram.

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.