[Tex/LaTex] Adding text to a rectangle


Wants to add text to a following rectangle. Also wants draw an another rectangle on the right side of the following rectangle sharing the boundary.



\hyphenation{op-tical net-works semi-conduc-tor}

%   \captionsetup{justification = centering}
        \coordinate (a1);
        \coordinate[right=150 of a1](a2);
        \coordinate[below=90 of a1](a3);
        \coordinate[right=150 of a3](a4);   
        \draw[ultra thick,rounded corners=10,green] ($(a4)-(80,20)$) 
rectangle +(80*2,20*2);%Rectangle rounded       

Best Answer


  • Remove unused packages, unused tikzlibraries and add needed package (tikz).
  • (Old: Add node{\Large text} right after rectangle to add text centered or just use nodes as follows ...)
  • Use node to draw the rectangular nodes with text, so you don't need to calculate any coordinates.
  • You can set minimum width=160, minimum height=40 to the desired size.
  • To let node B share the right boundary of A you can set option right=0 of a.




            myrectangle/.style={rectangle, draw, minimum width=160, minimum height=40, ultra thick, rounded corners=10, green}

            \node[myrectangle] (a) at (0,0) {\Large text};
            \node[myrectangle, right=0 of a] (b) {\Large B};


enter image description here