4

Ok, I've made the following diagram:

I want to add text labels to the various arrows (at the red points) and I want to ensure that the labels do not overlap the dotted lines, the arrow lines etc. So,

  • What is a good way to add labels to the lines (hopefully compatible with the way I've coded the lines)?
  • What is a good way to move the rectangles such that conflicts between the text of the labels and the lines of the rectangles and arrows are avoided?

The code is as follows:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{fit, arrows, calc, positioning}

\begin{document}

\tikzstyle{redRectangle} = [
    rectangle,
    draw,
    fill=red!20,
    node distance=0.65 cm,
    text width=7 em,
    text centered,
    rounded corners,
    minimum height=4 em,
    minimum width=3 cm,
    thick
]

\tikzstyle{blueRectangle} = [
    rectangle,
    draw,
    fill=blue!20,
    node distance=1.5 cm,
    text width=7 em,
    text centered,
    rounded corners,
    minimum height=4 em,
    minimum width=3 cm,
    thick
]

\tikzstyle{yellowRectangle} = [
    rectangle,
    draw,
    fill=yellow!20,
    node distance=1.5 cm,
    text width=7 em,
    text centered,
    rounded corners,
    minimum height=4 em,
    minimum width=3 cm,
    thick
]

\tikzstyle{greenRectangle} = [
    rectangle,
    draw,
    fill=green!20,
    node distance=1.5 cm,
    text width=7 em,
    text centered,
    rounded corners,
    minimum height=4 em,
    minimum width=3 cm,
    thick
]

\tikzstyle{blueDiamond} = [
    diamond,
    draw,
    fill=blue!20,
    node distance=1.5 cm,
    text width=7 em,
    text badly centered,
    inner sep=0pt,
    thick
]

\tikzstyle{blueEllipse} = [
    ellipse,
    draw,
    fill=blue!20,
    node distance=1.5 cm,
    text width=7 em,
    thick
]

\tikzstyle{container} = [
    rectangle,
    draw,
    inner sep=0.5 cm,
    dashed
]

\tikzstyle{empty} = [
]

\tikzstyle{line} = [
    draw,
    -latex',
    thick
]

\begin{tikzpicture}[auto]

    \node [empty](origin){};
    \node [redRectangle, right=of origin] (primaryxAODData) {primary xAOD data};
    \node [redRectangle, left=of origin] (primaryxAODMC) {primary xAOD MC};
    \node [blueRectangle, below=of origin](DxAOD0And1Lepton){DxAOD\\0 and 1 lepton};
    \node [blueRectangle, left=of DxAOD0And1Lepton] (DxAODMC) {DxAOD\\MC (also called TOPQ1)};
    \node [blueRectangle, right=of DxAOD0And1Lepton](DxAOD2Leptons){DxAOD\\2 leptons};
    \node [yellowRectangle, below=of DxAOD0And1Lepton](AnalysisTopPackage){AnalysisTop package\\TTHbbLeptonic};
    \node [blueRectangle, below=of AnalysisTopPackage](Mini-xAODorflatn-tuple){Mini-xAOD or flat n-tuple};
    \node [greenRectangle, below=of Mini-xAODorflatn-tuple](plots){plots};

    \node [container, fit=(primaryxAODData)(origin)(primaryxAODMC)](container1){};
    \node [container, fit=(AnalysisTopPackage)](container2){};
    \node [container, fit=(plots)](container3){};

    \path [line] (primaryxAODMC) -- (DxAODMC);
    \path [line] (primaryxAODData) -- (DxAOD0And1Lepton);
    \path [line] (primaryxAODData) -- (DxAOD2Leptons);

    \path [line] (DxAODMC) -- (AnalysisTopPackage);
    \path [line] (DxAOD0And1Lepton) -- (AnalysisTopPackage);
    \path [line] (DxAOD2Leptons) -- (AnalysisTopPackage);

    \path [line] (AnalysisTopPackage) -- (Mini-xAODorflatn-tuple);
    \path [line] (Mini-xAODorflatn-tuple) -- (plots);

    \node at (container1.north)[above]{production system};
    \node at (container2.south east)[right]{user grid or local};
    \node at (container3.south east)[right]{user grid or local};

\end{tikzpicture}

\end{document}
Andrew Swann
  • 95,762
d3pd
  • 1,718

1 Answers1

5

Next code shows you some examples:

\path [line] (primaryxAODMC) -- (DxAODMC) node[fill=white, pos=0.7, right=2mm]{label A};

draws a line between primaryxAODMC.center and DxAODMC.center and adds a node with text label A to the right of position 0.7 (1 is total path lenght) of this path. The node has a fill=white background which could cover any previous path.

You can change fitting nodes if you adjust their inner sep, as in:

\node [container, fit=(plots), label={[anchor=west]south east:user grid or local}, inner sep=7mm](container3){};

Instead of new nodes for labels for dashed nodes, you can use label node option:

    \node [container, fit=(primaryxAODData)(origin)(primaryxAODMC), label=above:production system](container1){};

And instead of redRectangle, blueRectangle, ... you can define a Rectangle with a parameter which will later define its color.

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{fit, arrows, calc, positioning}

\begin{document}

\tikzstyle{Rectangle} = [
    rectangle,
    draw,
    fill=#1!20,
    node distance=1.5 cm,
    text width=7 em,
    text centered,
    rounded corners,
    minimum height=4 em,
    minimum width=3 cm,
    thick
]

\tikzstyle{blueDiamond} = [
    diamond,
    draw,
    fill=blue!20,
    node distance=1.5 cm,
    text width=7 em,
    text badly centered,
    inner sep=0pt,
    thick
]

\tikzstyle{blueEllipse} = [
    ellipse,
    draw,
    fill=blue!20,
    node distance=1.5 cm,
    text width=7 em,
    thick
]

\tikzstyle{container} = [
    rectangle,
    draw,
    inner sep=0.2 cm,
    dashed
]

\tikzstyle{empty} = [
]

\tikzstyle{line} = [
    draw,
    -latex',
    thick
]

\begin{tikzpicture}[auto]

    \node [empty](origin){};
    \node [Rectangle=red, right=of origin] (primaryxAODData) {primary xAOD data};
    \node [Rectangle=red, left=of origin] (primaryxAODMC) {primary xAOD MC};
    \node [Rectangle=blue, below=of origin](DxAOD0And1Lepton){DxAOD\\0 and 1 lepton};
    \node [Rectangle=blue, left=of DxAOD0And1Lepton] (DxAODMC) {DxAOD\\MC (also called TOPQ1)};
    \node [Rectangle=blue, right=of DxAOD0And1Lepton](DxAOD2Leptons){DxAOD\\2 leptons};
    \node [Rectangle=yellow, below=of DxAOD0And1Lepton](AnalysisTopPackage){AnalysisTop package\\TTHbbLeptonic};
    \node [Rectangle=blue, below=of AnalysisTopPackage](Mini-xAODorflatn-tuple){Mini-xAOD or flat n-tuple};
    \node [Rectangle=green, below=of Mini-xAODorflatn-tuple](plots){plots};

    \node [container, fit=(primaryxAODData)(origin)(primaryxAODMC), label=above:production system](container1){};
    \node [container, fit=(AnalysisTopPackage), label={[anchor=west]south east:user grid or local}](container2){};
    \node [container, fit=(plots), label={[anchor=west]south east:user grid or local}, inner sep=7mm](container3){};

    \path [line] (primaryxAODMC) -- (DxAODMC) node[fill=white, pos=0.7, right=2mm]{label A};
    \path [line] (primaryxAODData) -- (DxAOD0And1Lepton) node[midway, left]{label B};
    \path [line] (primaryxAODData) -- (DxAOD2Leptons)node[anchor=center,fill=white, midway]{label C};

    \path [line] (DxAODMC) -- (AnalysisTopPackage);
    \path [line] (DxAOD0And1Lepton) -- (AnalysisTopPackage);
    \path [line] (DxAOD2Leptons) -- (AnalysisTopPackage);

    \path [line] (AnalysisTopPackage) -- (Mini-xAODorflatn-tuple);
    \path [line] (Mini-xAODorflatn-tuple) -- (plots);

%    \node at (container1.north)[above]{production system};
%    \node at (container2.south east)[right]{user grid or local};
%    \node at (container3.south east)[right]{user grid or local};

\end{tikzpicture}

\end{document}

enter image description here

Ignasi
  • 136,588
  • Thank you very much for your assistance on this and for your tips on making some of the objects more generalised. Your approach does indeed work.

    Would you happen to know if there is a more automated approach to creating diagrams like this in TikZ (so that I wouldn't have to edit sizes and whatnot in order to avoid overlap of elements)?

    – d3pd Mar 02 '15 at 11:09
  • @d3pd Glad to help you. I don't know any automatic tool. matrix nodes can help you when the diagram has a regular distribution, but distance between nodes and where to place labels is always up to your criteria. – Ignasi Mar 02 '15 at 11:29