3

Is it possible in the following example to set text in drawn boxes?

enter image description here

This is my code i hope it will helps.

\documentclass[12pt,a4paper]{article}
\usepackage{tikz}

\begin{document}

\begin{center}
\begin{tikzpicture}[scale=0.33]
\draw[black, fill=blue,fill opacity=0.5, line width=2pt]  (0,0) -- (0,20) -- (42.5,20) -- (42.5,15) -- (5,15) -- (5,0) -- (0,0) -- cycle; %Vendor Specific Extensions
\draw[black, fill=green,fill opacity=0.5, line width=2pt] (7.5,0) -- (7.5, 12.5) -- (42.5, 12.5) -- (42.5, 7.5) -- (12.5, 7.5) -- (12.5, 0) -- (7.5,0) -- cycle; %Collaboration Models

\draw[line width=2pt] (15,0) -- (15,5) -- (20,5) -- (20,0) -- (15,0); %DA
\draw[line width=2pt] (22.5,0) -- (22.5,5) -- (27.5,5) -- (27.5,0) -- (22.5,0); %AC
\draw[line width=2pt] (30,0) -- (30,5) -- (35,5) -- (35,0) -- (30,0); % HA
\draw[line width=2pt] (37.5,0) -- (37.5,5) -- (42.5,5) -- (42.5,0) -- (37.5,0); %Prg

\draw[line width=2pt] (0,-2.5) -- (42.5,-2.5) -- (42.5,-7.5) -- (0,-7.5) -- (0,-2.5); %Base Services
\draw[line width=2pt] (0,-10) -- (18.75,-10) -- (18.75,-15) -- (0,-15) -- (0,-10); %Transport
\draw[line width=2pt] (23.75,-10) -- (42.5,-10) -- (42.5,-15) -- (23.75,-15) -- (23.75,-10); %Meta Model

\end{tikzpicture}
\end{center}
\end{document}
  • 1
    Yes it is. But are you already familiar with the node concept in TikZ ? – percusse Jul 6 '17 at 0:45
  • no, i'm an rookie on tkiz. was the first try to draw this diagram – christoph Jul 6 '17 at 0:47
  • 2
    I see let me try to write an answer. Welcome to the site by the way. – percusse Jul 6 '17 at 0:47
  • this way was very time consuming...:(. thanks a lot – christoph Jul 6 '17 at 0:53
  • 1
    If you say \node [draw] at (3,4) {Text to go into node}; you'll get boxed text. If you say \node [draw, minimum width=50mm, minimum height=10mm] at ..., you can set the width and height of the box. – cfr Jul 6 '17 at 1:01
2

Like this:

enter image description here

\documentclass[12pt, tikz, margin=5mm]{standalone}

\begin{document}
    \begin{tikzpicture}[scale = 0.33,
     every node/.style = {font=\Large, text=black, text opacity=1},
                   line width = 2pt
                        ]
\draw[fill=blue,fill opacity=0.5]  
    (0,0)     -- (0,20) --  node[below=5mm] {Vendor Specific Extensions} (42.5,20) -- 
    (42.5,15) -- (5,15) -- (5,0) -- cycle; %Vendor Specific Extensions
\draw[fill=green,fill opacity=0.5] 
    (7.5,0)     -- (7.5, 12.5) --   node[below=5mm] {Collaboration Models} (42.5, 12.5) -- 
    (42.5, 7.5) -- (12.5, 7.5) -- (12.5, 0) -- cycle; %Collaboration Models
%
\draw  (15,0)   rectangle (20,5)   node[midway] {DA}; %DA
\draw  (22.5,0) rectangle (27.5,5) node[midway] {AC}; %AC
\draw  (30,0)   rectangle (35,5)   node[midway] {HA}; % HA
\draw  (37.5,0) rectangle (42.5,5) node[midway] {Prg}; %Prg
%
\draw  (0,-2.5) rectangle  (42.5,-7.5)  node[midway] {Base Services}; %Base Services
\draw  (0,-10)  rectangle  (18.75,-15)  node[midway] {Transport}; %Transport
\draw  (23.75,-10) rectangle (42.75,-15) node[midway] {Meta Model}; %Meta Model
    \end{tikzpicture}
\end{document}

Of course, using nodes with rectangle shape instead of drawing rectangles to which is added nodes with text, gives more concise code :)

2

In TikZ there are objects that go by the name nodes. These are in a nut shell text boxes with different shapes (rectangle, circle and so on). Their size can be adjusted and their colors line types etc. can be altered by supplying options to them. The L shapes are not supported yet but you can still place nodes over them to put text.

I've modified your example a bit by dividing everything roughly by 3 to get rid of the 0.333 scaling

\documentclass[12pt,a4paper]{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\draw[black, fill=blue,fill opacity=0.5, line width=2pt]  (0,0) -- (0,6) -- (14,6) -- (14,5) -- (1.5,5) -- (1.5,0) -- (0,0) -- cycle; %Vendor Specific Extensions
\draw[black, fill=green,fill opacity=0.5, line width=2pt] (2.5,0) -- (2.5, 4.5) -- (14, 4.5) -- (14, 2.5) -- (4.5, 2.5) -- (4.5, 0) -- (2.5,0) -- cycle; %Collaboration Models

\node[minimum size=1cm,draw,scale=2,line width=2pt] (da) at (6.5, 1) {DA}; %DA
\node[minimum size=1cm,draw,scale=2,line width=2pt] (da) at (9.5, 1) {AC}; %DA
\end{tikzpicture}
\end{document}

Here you can see that I'm just describing the box content with {} and giving a (center of the box) position by at (.,.) and bunch of relevant options to the \node command.

There are lots of possibilities but this is basically the essence of the node stuff that you can place around. When you are done with this type of machinery, you can gradually get better at the specifics. enter image description here

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.