3

I'm using Tikz for first time and I'm trying to make this graph but... It's being kinda hard.

enter image description here

1. About positioning:

I'm using relative positioning and I think that's not a good idea (look at orange lines), but I don't know how to do it better. For instance:

%Group 1
\node[cuadrado] (g1_1) {$y_m$};
\node[circulo] (g1_2) [left of=g1_1] {$y_m$};
\node[circulo] (g1_3) [right of=g1_1] {$\neg y_m$};
\node[cuadrado] (g1_4) [above left of=g1_2] {$y_m$};
...

Perhaps using absolute positions within the sheet?

enter image description here

On the other hand, the edge elements (the text) are not placed correctly on the right side (look at green circles). Is it possible to make them look like a mirror (compare to the left side)?

2. About dimension of the nodes

Is it possible to maintain the fixed dimension of the nodes? When I have a lot of text inside a node I don't know how to solve it. For example here, on the right side of the big pic:

enter image description here

3. About general tips

Do you guys think there is an easier way to do that drawing? As I say I am not very familiar with Tikz. I think the best option is to split the big pic into two parts (left side and right side), but I don't know if it's "easy" to make the whole drawing to fit on one sheet (that would be the ideal case).

Too many questions, sorry.

Tips, advices, links to help me are welcome! Thanks in advance.

1 Answer 1

5

Compliments for trying TikZ for the first time with such a complicated graph!

  1. Instead of using relative positions, you could use a TikZ matrix. It doesn't seem easy, but it is. The matrix is like a tabular, and you can refer to each cell with matrixname-rownumber-columnnumber. For example, in the following code, m-3-2 is the node at the 3rd row and 2nd column of matrix m.
    As for the symmetric arrows, you can play with the label node positions. Always see the example below.
  2. To have nodes of the same dimensions, you can set them with minimum width, text width, text height, text depth. I've used an oval shape for the circle with large text. See again the example below.
  3. I think you'll find Prof. van Duck's articles helpful. Read Section 2 here for Tikz matrix and Section 3 here for TikZ in general.

Of course the example is not complete, but I think you'll find some useful tips here:

\documentclass[border=1cm]{standalone} 
\usepackage{amsmath}
\usepackage{tikz}
\usetikzlibrary{matrix}
\usetikzlibrary{arrows.meta, bending}
\tikzset{
    mymatr/.style = {
        matrix of math nodes,
        row sep=30pt,
        column sep=10pt,
        nodes={cuadrado}
        },
    base/.style = {
        draw, 
        very thick,
        text=black,
        text centered,
        text height=13pt,
        text depth=7pt,
        },
    cuadrado/.style = {
        blue, 
        fill=blue!10!white,
        base, 
        minimum width=30pt,
        },
    circulo/.style = {
        cyan, 
        fill=cyan!10!white,
        circle,
        base, 
        text width=20pt,
        inner sep=1pt,
        },      
    oval/.style = {
        red, 
        fill=red!10!white,
        rounded corners=14,
        base, 
        minimum width=30pt,
        inner sep=4pt,
        },      
    }
    
\begin{document} 
\begin{tikzpicture}[>=Stealth]
\matrix[mymatr] (m) {
    && x^1_1 &[-16pt]&[-16pt] \neg x^1_1 &&&[30pt]\\[20pt]
    x_1 && x^k_1 && \neg x^k_1 && \neg x_1 \\ 
    & |[circulo]|x_1 && x_1 && |[circulo]|\neg x_1 \\
    x_1 &&&&&& \neg x_1 \\[-40pt]
    && x^1_m && \neg x^1_m &&&|[oval]|c_1\vee\neg x_n\vee y_1\\[20pt]
    x_n && x^k_m && \neg x^k_m && \neg x_n \\ 
    & |[circulo]|x_n && x_n && |[circulo]|\neg x_n \\
    x_n &&&&&& \neg x_n \\ 
    };
\draw[->] (m-3-2) -- node[right=4pt] {$1$} (m-4-1);
\draw[->] (m-3-2) -- node[below left] {$n-1$} (m-2-1);
\draw[->] (m-3-2) to[bend left] node[above=30pt,left=-8pt] {$1$} (m-1-3);
\draw[->] (m-3-2) -- node[left=4pt] {$1$} (m-2-3);
\draw[->] (m-3-2) -- node[below] {$k+1$} (m-3-4);

\draw[->] (m-3-6) -- node[left=4pt] {$1$} (m-4-7);
\draw[->] (m-3-6) -- node[below right] {$n-1$} (m-2-7);
\draw[->] (m-3-6) to[bend right] node[above=30pt,right=-8pt] {$1$} (m-1-5);
\draw[->] (m-3-6) -- node[right=4pt] {$1$} (m-2-5);
\draw[->] (m-3-6) -- node[below] {$k+1$} (m-3-4);

\draw[->] (m-7-2) -- node[right=4pt] {$1$} (m-8-1);
\draw[->] (m-7-2) -- node[below left] {$n-1$} (m-6-1);
\draw[->] (m-7-2) to[bend left] node[above=30pt,left=-8pt] {$1$} (m-5-3);
\draw[->] (m-7-2) -- node[left=4pt] {$1$} (m-6-3);
\draw[->] (m-7-2) -- node[below] {$k+1$} (m-7-4);


\draw[->] (m-7-6) -- node[left=4pt] {$1$} (m-8-7);
\draw[->] (m-7-6) -- node[below right] {$n-1$} (m-6-7);
\draw[->] (m-7-6) to[bend right] node[above=30pt,right=-8pt] {$1$} (m-5-5);
\draw[->] (m-7-6) -- node[right=4pt] {$1$} (m-6-5);
\draw[->] (m-7-6) -- node[below] {$k+1$} (m-7-4);

\draw[->] (m-5-8) to[in=50, out=90] node[right=6pt] {$2M-2$} (m-1-3.70);
\end{tikzpicture}
\end{document}

enter image description here

3
  • First of all, thank you so much for answering! You can check the result of the graph here: mdpi.com/2227-7390/9/14/1599
    – Joncarre
    Commented Dec 5, 2021 at 12:30
  • 1
    @Joncarre Sorry for having arrived late :D You did a great job!
    – CarLaTeX
    Commented Dec 5, 2021 at 12:46
  • 1
    @Joncarre I like the idea of the final result behind the graph :)
    – JeT
    Commented Dec 7, 2021 at 19:16

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .