TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to draw a small chart showing a modular C++-program. I don't know where to start.

+-------------\  **    +------------\        + compiled src --+
| module.hpp  |\   **  | main.cpp   |\       |                |
+-------------+-+    **+------------+-+      | void func()    |
|               |      | #include "...|  ==> | int main() {   |
| void func();  |    **| int main() { |      |   ...          |
|               |  **  |   ...        |      |                |
+---------------+**    +--------------+      +----------------+

The module.hpp should visually "go into" the #include-line in main.cpp, so I thought about connecting lines that I draw as **-lines.

I will replace the text in the boxes with a bit better text, and probably add another box to the right for the applied compiler.

I can not think of what should be nodes here.

share|improve this question
you should look into {tikz-uml} – Sean Allred Jan 16 '14 at 20:56
You can also play with \fbox, \parbox, \left. \right\rbrace and \rarrow and put the whole thing into an equation. But to do the triangle you need tikz. – John Kormylo Jan 17 '14 at 15:22
@towi have you found a solution or is this still open? – Paul Gessler Mar 2 '14 at 3:29
@PaulGessler I found a solution but did it a bit different. I think my current visualization is actually better then what I first planned. – towi Mar 2 '14 at 15:00
@towi great! You could either post your solution as a self-answer if you think it will be helpful for future visitors to the site, or close the question if you think the solution is too specific to your situation. It's up to you to decide. :) – Paul Gessler Mar 2 '14 at 15:02

For the record, I found a satisfactory solution. I modified a bit how I wanted to display the "inclusion" and I am quite satisfied with it. Just to let you know, if anyone wants to try the same.




\resizebox {\columnwidth} {!} {    % (2) scale to exact column width
      background rectangle/.style={fill=black!10}, show background rectangle,

\tikzstyle{mybox} = [draw, fill=black!0, very thick,
    rectangle, inner sep=8pt, inner ysep=16pt]
\tikzstyle{fancytitle} =[fill=black!0, draw, very thick, text=black!100, rectangle, inner xsep=6pt,yshift=7.2pt,right=0pt]
\tikzstyle{modul} =[text=black!100, rectangle, inner sep=6pt]
\tikzstyle{cpp} =[fill=black!0, draw=black!30, thick]
\tikzstyle{hpp} =[fill=black!0, draw, thick]

  \node at (0,0) (main) [modul,cpp] {%
      \#include "teil1.hpp" \\ 
      \#include "teil2.hpp" \\ 
      \#include "const.hpp" \\ 
      int main() \{ ... \} 
  \node[fancytitle,cpp] at (main.north west) {main.cpp};

  \node [below=of main.south east,xshift=-4ex] (teil1hpp) [modul,hpp] {%
      int func1(); \\
      static const int M=10;
  \node[fancytitle,hpp] at (teil1hpp.north west) (a1) {teil1.hpp};

  \node [right=of teil1hpp.north east, anchor=north west] (teil1cpp) [modul,cpp] {%
      \#include "teil1.hpp" \\ 
      \#include "{}util.hpp" \\ 
      int func1() \{ ... \};
  \node[fancytitle,cpp] at (teil1cpp.north west){teil1.cpp};

  \node [below=of teil1hpp,yshift=-12pt] (teil2hpp) [modul,hpp] {%
      \#include "{}util.hpp" \\ 
      \#include "const.hpp" \\ 
      int func2(); \\
          int data[Z];
  \node[fancytitle,hpp] at (teil2hpp.north west) {teil2.hpp};

  \node [right=of teil2hpp.north east, anchor=north west] (teil2cpp) [modul,cpp] {%
      \#include "teil2.hpp" \\ 
      int func2() \{ ... \}; \\
          int data[Z] = \{\};
  \node[fancytitle,cpp] at (teil2cpp.north west) {teil2.cpp};

  \node [below=of teil2hpp] (utilhpp) [modul,hpp] {%
      int calcLen();
  \node[fancytitle,hpp] at (utilhpp.north west) (a2) {util.hpp};

  \node [right=of utilhpp.north east, anchor=north west] (utilcpp) [modul,cpp] {%
      \#include "{}util.hpp" \\ 
      \#include "const.hpp" \\ 
      int calcLen() \{ ... \};
  \node[fancytitle,cpp] at (utilcpp.north west) {util.cpp};

  \node [right=of utilcpp.north east, anchor=north west] (consthpp) [modul,hpp] {%
      static const int X=1; \\
      static const int Y=2; \\
      static const int Z=3;
  \node[fancytitle,hpp] at (consthpp.north west) {const.hpp};


 \path (main.south west) -- (a1.north west) node[midway] (aa) {};
 \path (main.south west)[xshift=-3ex] |- (aa) node[midway] (aaa) {};
   \draw[ultra thick,draw=black!20] (aaa) -- ([xshift=3ex]aaa -| consthpp.north east);

 \path (teil2hpp.south west) -- (a2.north west) node[midway] (bb) {};
   \draw[ultra thick,draw=black!20] (aaa |- bb) -- ([xshift=3ex]bb -| consthpp.north east);

 \draw[arrows={-triangle 45}]   (main.south west) |- (teil1hpp.west);
 \draw[arrows={-triangle 45}]   (main.south west) |- (teil2hpp)  ;
 \draw[arrows={-triangle 45}]   (main.east) -| ([xshift=1cm]consthpp.north);
 \draw[arrows={-triangle 45}]   (teil1cpp.south west)  -- (utilhpp.north east);
 \draw[arrows={-triangle 45}]   ([yshift=1.1cm]teil2cpp.west)  -- (teil1hpp);
 \draw[arrows={-triangle 45}]   (teil2hpp) edge [out=-20] (consthpp.north west); 
 \draw[arrows={-triangle 45}]   (utilcpp) -- (consthpp);

 \draw[thick,dashed,black!50]   (teil1cpp.north west) -- (teil1hpp.north east);
 \draw[thick,dashed,black!50]   (teil2cpp.north west) -- (teil2hpp.north east);
 \draw[thick,dashed,black!50]   (utilcpp.north west) -- (utilhpp.north east);

share|improve this answer

Your Answer


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.