I don't really get the question so I hope this is what you wanted. If you include a full document (such that we copy paste and see the problem on our systems) things are much more easier.
Here, you can change the default setting within a scope but your block
style had a node distance
which was resetting every time it is issued. I've made it 2mm such that we can see the difference easier.
\documentclass[tikz]{standalone}
\usetikzlibrary{arrows,shapes.geometric,positioning}
\begin{document}
\begin{tikzpicture}[decision/.style={diamond, draw, text width=4.5em, text badly centered, node distance=3.5cm, inner sep=0pt},
block/.style ={rectangle, draw, text width=6em, text centered, rounded corners, minimum height=4em, minimum height=2em},
cloud/.style ={draw, ellipse, minimum height=2em},
line/.style ={draw,-latex'},
node distance = 1cm,
auto]
\node [block] (1st) {1st};
\node [block, right= of 1st] (2nd1) {2nd1};
\begin{scope}[node distance=2mm and 10mm]%Here we change it for everything inside this scope
\node [block, above= of 2nd1] (2nd2) {2nd2};
\node [block, below= of 2nd1] (2nd3) {2nd3};
\node [block, right= of 2nd1] (3rd1) {3rd1};
\node [block, above= of 3rd1] (3rd2) {3rd2};
\node [block, above= of 3rd2] (3rd3) {3rd3};
\end{scope}
\node [block, below= of 3rd1] (3rd4) {3rd4};
\node [block, below= of 3rd4] (3rd5) {3rd5};
\path [line] (1st) -- (2nd1);
\path [line] (2nd1) -- (2nd2);
\path [line] (2nd1) -- (2nd3);
\path [line] (2nd2) -- (3rd3);
\path [line] (2nd1) -- (3rd1);
\path [line] (1st) -- (2nd1);
\end{tikzpicture}
\end{document}
![enter image description here](https://i.stack.imgur.com/SWssd.png)
A second attempt, this time making some assumptions on the layout.
I assume you want the hyper-edge to always be aligned to the "lonely" node of the triplets (e.g. c
in ({a,b},{c})
and ({c},{a,b})
).
Since you seem to need fine control on the positioning of the nodes I suggest the following: first you place named nodes with manual positioning (using whichever method you prefer, from absolute coordinates to relative positioning);
then you specify the hyperedges and the corresponding arcs get created.
Here's a macro that can help you with the second step:
\newcommand{\hyperedge}[4][180]{
\draw (#2.#1) ++(#1:.5) edge (#2) edge (#3) edge (#4);
}
It takes 4 arguments (first optional): \hyperedge[angle]{c}{a}{b}
draws the edges assuming that c
is the lonely node and requires you to specify the angle at which the hyperedge should stick out of it.
The definition of the macro works by moving to the right/left border of the lonely node (this is accomplished by (#2.#1)
which moves to the border of the node #2
at angle #1
), then move right/left by .5
which is the coordinate of the "centre" of the edge; then this "centre" is connected with the nodes using the edge
action.
Here's your second example using tikz and my macro:
\documentclass{standalone}
\usepackage{tikz}
\newcommand{\hyperedge}[4][180]{
\draw (#2.#1) ++(#1:.5) edge (#2) edge (#3) edge (#4);
}
\begin{document}
\begin{tikzpicture}[
y=.7cm, x=1cm,
every edge/.append style={thick}
]
\node (a) at (-1,1) {a};
\node (b) at (-1,-1) {b};
\node (c) at (0,0) {c};
\node (d) at (1,1) {d};
\node (e) at (1,-1) {e};
\node (g) at (2,-2) {g};
\hyperedge{c}{b}{a}
\hyperedge[0]{c}{d}{e}
\hyperedge{g}{b}{e}
\end{tikzpicture}
\end{document}
Which is rather readable and easy to extend.
You can elaborate on this by using other means to specify the angle (other derived macros) or enriching it with custom styles.
Another option for the placement of the "centre" of the hyperedge is barycentric coordinates:
\newcommand{\hyperedge}[3]{
\draw (barycentric cs:#1=1,#2=1,#3=1) edge (#1) edge (#2) edge (#3);
}
Note that this does not require the angle
argument.
Best Answer
Here is a solution for the graph of your example with
n
even. Ifn
is odd there is no such coloring.I use
math
library to make the logic, but if you wan you can replace this part of the code by vanilla tex solution.With
mygraph=10
:EDIT (after this answer has been accepted): Here is a code without
tikzmath
and such that the node counter is automatically reset at the begining of the graph. This allows you to draw more than one graph without reseting the counter manually.