3

Good day every one

I am currently having some trouble positioning a stack of nodes grouped in a scope. I must be proceeding badly but here is my code :

 \documentclass{standalone}
\usepackage[french]{babel}
\usepackage[T1]{fontenc}
\usepackage{tikz}


\usepackage{lmodern}
\usetikzlibrary{positioning}
\newcommand{\nom}[1]{\textsc{#1}}

\def\nodehdist{2cm}
\begin{document}
\begin{tikzpicture}

\begin{scope}[local bounding box=seniors]
\node(n_anna) at (0,0){\nom{untel}};
\node[align=center,below=0 of n_anna](anna) at (n_anna.south){
\scriptsize Gestionnaire Paie\\
\scriptsize Collaboratrice};

\node(n_remi) [right=\nodehdist of n_anna]{\nom{untel}};
\node[align=center,below=0 of n_remi] at (n_remi.south){
\scriptsize Responsable portefeuille};

\node(n_guilhem) [right=\nodehdist of n_remi]{\nom{untel}};
\node[align=center,below=0 of n_guilhem] at (n_guilhem.south){
\scriptsize Responsable paie\\
\scriptsize Collaborateur};

\end{scope}

\begin{scope}[shift={(0,2cm)}]
\node(n_axel) at (0,0){\nom{mister}};
\node[align=center,below=0 of n_axel]{
\scriptsize Expert-Comptable};

\node(n_sarah)[right=5*\nodehdist of n_axel]{\nom{miss}};
\node[align=center,below=0 of n_sarah]{
\scriptsize Expert-Comptable | Commissaire aux Comptes};
\end{scope}
\end{tikzpicture}
\end{document}

As a result, I would like to get the "mister" and "miss" nodes centered as a whole node to the center of the whole formed by the three nodes below. As you can see on my example, "mister" and "miss" nodes are centered in some curious way I do not get. I was wondering if this could be solved with any relative-positioning solution?

Edit : I have tried this too as a clearer (or so did I wish) example :

\documentclass{standalone}
\usepackage[french]{babel}
\usepackage[T1]{fontenc}
\usepackage{tikz}


\usepackage{lmodern}
\usetikzlibrary{positioning}
\newcommand{\nom}[1]{\textsc{#1}}

\def\nodehdist{2cm}
\begin{document}
\begin{tikzpicture}
\node[fill=red!25](Node) at(0,0){%
\begin{tikzpicture}
\node(node1) at (0,0){node 1};
\node[right=of node1](node2){node 2};
\node[right=of node2]{node 3};
\end{tikzpicture}
};

\node[fill=blue!25,above=of Node]{
\begin{tikzpicture}
\node(node4) at (0,0){node 4};
\node[right=of node4](node5){node 5};
\end{tikzpicture}
};
\draw (node1)--(node4);

\end{tikzpicture}
\end{document}

I seek to positionate some clusters of nodes (here red and blue) relatively to each other while the nodes inside them are themeselves set relatively to each other(node 1, node 2 and node 3 on one side; node 4 and node 5 on the other side). In this example that purpose is reached, but if I try to link node 1 to node 4, the result is weird.

Thanks for any help

  • If I completely missed the mark with my answer, can you describe in more detail what you're after, perhaps even add a sketch of the desired output? – Torbjørn T. Oct 2 '15 at 18:14
3

I understand you want to draw some nodes (three in your example, but could be more) and place two nodes over them centered respect the whole width of lower nodes (scope).

Following code shows a possible solution. Place as many nodes as you want without any scope. Once placed, declare a fit node and which encompasses all what you want (this fitting node drawn in code, but just to show it). After that place two upper nodes into a matrix which position is fixed according fitting node.

If you need to insert more nodes in lower group and they makes lower part wider, add them to fit list and upper matrix will be always centered.

\documentclass[border=2mm]{standalone}
\usepackage[french]{babel}
\usepackage[T1]{fontenc}
\usepackage{tikz}


\usepackage{lmodern}
\usetikzlibrary{positioning,fit,matrix}
\newcommand{\nom}[1]{\textsc{\normalsize #1}}

\def\nodehdist{2cm}
\begin{document}
\begin{tikzpicture}[mynode/.style={draw, align=center, font=\scriptsize}]

%\begin{scope}[local bounding box=seniors]
\node[mynode] (n_anna) {\nom{untel}\\Gestionnaire Paie\\
Collaboratrice};

\node[mynode, right=\nodehdist of n_anna] (n_remi) {\nom{untel} \\ Responsable portefeuille};

\node[mynode, right=\nodehdist of n_remi] (n_guilhem) {\nom{untel}\\ Responsable paie\\
Collaborateur};

\node[mynode, below left= of n_remi] (newnode1) {\nom{untel}\\ xxxxxx xxxxx};

\node[mynode, below right= 1cm and 8mm of n_guilhem] (newnode2) {\nom{untel}\\ yyyyy yyyyy\\ yyyy yyyy};

\node[draw, fit=(n_anna) (n_guilhem) (newnode1) (newnode2)] (seniors) {}; 
%\end{scope}


\node[draw, matrix, column sep=1cm, above=1cm of seniors] (over-seniors) {\node[mynode]
{\nom{mister}\\ Expert-Comptable}; & \node[mynode]{\nom{miss}\\Expert-Comptable | Commissaire aux Comptes};\\};

\end{tikzpicture}
\end{document}

enter image description here

3

This may be helpful. I add the upper two nodes in a matrix, and position this relative to the scope already defined. You can of course use a matrix for the lower three nodes as well.

\documentclass{standalone}
\usepackage[french]{babel}
\usepackage[T1]{fontenc}
\usepackage{tikz}


\usepackage{lmodern}
\usetikzlibrary{positioning}
\newcommand{\nom}[1]{\textsc{#1}}

\def\nodehdist{2cm}
\begin{document}
\begin{tikzpicture}

\begin{scope}[local bounding box=seniors]
\node(n_anna) at (0,0){\nom{untel}};
\node[align=center,below=0 of n_anna](anna) at (n_anna.south){
\scriptsize Gestionnaire Paie\\
\scriptsize Collaboratrice};

\node(n_remi) [right=\nodehdist of n_anna]{\nom{untel}};
\node[align=center,below=0 of n_remi] at (n_remi.south){
\scriptsize Responsable portefeuille};

\node(n_guilhem) [right=\nodehdist of n_remi]{\nom{untel}};
\node[align=center,below=0 of n_guilhem] at (n_guilhem.south){
\scriptsize Responsable paie\\
\scriptsize Collaborateur};
\end{scope}

\matrix (m) [above=of seniors,column sep={5*\nodehdist,between origins}] {
\node[align=center](n_axel) {\nom{mister}\\ \scriptsize Expert-Comptable}; &
\node[align=center](n_sarah){\nom{miss}\\\scriptsize Expert-Comptable | Commissaire aux Comptes}; \\
};
\end{tikzpicture}
\end{document}
  • your solution is interesting but that is not quite what I look for : if I come to add some nodes in the scope, the nodes mister and miss will be completely set away, despite my wish to positionate them relatively to each other. NB : I cannot add directly the pdf I get. Could you tell me how to do that so that I can try to be a little clearer? – Frednight Oct 2 '15 at 19:17
  • @Frednight I just take a screenshot of the PDF. – Torbjørn T. Oct 2 '15 at 19:18
2

Another possibilities is to use multi part nodes and escape use of scopes:

    \documentclass[border=5mm,
                   tikz]{standalone}
    %\usepackage[french]{babel}
    \usepackage[T1]{fontenc}

    \usepackage{lmodern}
    \usetikzlibrary{calc,positioning,shapes.multipart}
    \newcommand{\nom}[1]{\textsc{#1}}

    \begin{document}
        \begin{tikzpicture}[
         node distance = 5 mm and 7mm,
    every node/.style = {
        shape=rectangle split, rectangle split parts=2,
    %    draw, % <-- in case that you like to see node's borders
        align=center, text width=34mm, outer sep=0mm}
                            ]
\linespread{0.8}
\node   (mister) {\nodepart{one}    \nom{mister}
                  \nodepart{two}\scriptsize    Expert-Comptable};
\node[text width=62mm, right=of mister]   
        (miss)  {\nodepart{one}    \nom{miss}
                 \nodepart{two}\scriptsize    Expert-Comptable | Commissaire aux Comptes};

\node[below=of $(mister.south west)!0.5!(miss.south east)$] (middle)  
        {\nodepart{one}    \nom{untel}
         \nodepart{two}\scriptsize    Responsable portefeuille};

\node[left=of middle]
        {\nodepart{one}    \nom{untel}
         \nodepart{two}\scriptsize    Gestionnaire Paie Collaboratrice};

\node[right=of middle]  
        {\nodepart{one}    \nom{untel}
         \nodepart{two}\scriptsize    Responsable paie Collaborateur};
    \end{tikzpicture}   
\end{document}

Result:

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.