10

I want to draw partition lattice for n=4 like thispartition lattice for n=4

I was looking for informations how to do it and i found package tikz-cd which i think could be useful but the only thing I managed to do by myself is to draw a single rectangle using:

    \begin{tikzcd}
    \node[regular polygon, regular polygon sides=4, minimum size=1cm] (A){};
    \filldraw[line width=3pt, gray, line join=round] (A.corner 1)--(A.corner 2)--(A.corner 3)--(A.corner 4)--cycle;
    \end{tikzcd}

Which gives an output like this;

enter image description here

I have also found how to draw arrow using tikzcd:

\begin{tikzcd}
A \arrow[rd] \arrow[r] & B \\
& C
\end{tikzcd}

enter image description here

Now I have no idea how to connect this two things. Maybe this is completely pointless approach to this problem and there is a better way to do it.

2
  • 1
    You don’t need to use tikz-cd for this. It may be easier (especially considering the non-aligned dice in the middle) to just position the nodes with, for example, \node[...] at (1,0) (A) {}; where (1,0) ist the coordinate in cm of the node, and later connect the nodes with \draw (A) -- (B); where (A) and (B) are the names of previously defined nodes. – Jasper Habicht Mar 5 at 13:10
  • Great design! I agree with Jasper. You will also need the use of foreach. – projetmbc Mar 5 at 13:21
7

I think there has to be a simpler way to do it, but here is a possible solution. I changed the position of some "dice" slightly to improve the visibility of the lines connecting them. And these lines are all straight, some can be curved but then they would have to be removed from the \foreach.

\documentclass[border=2mm]{standalone}
\usepackage    {ifthen}
\usepackage    {tikz}
\usetikzlibrary{calc}

% Colors
\definecolor{colorB} {HTML}{E57FE4}
\definecolor{colorC1}{HTML}{F8B87F}
\definecolor{colorC2}{HTML}{CCADA2}
\definecolor{colorD} {HTML}{7FD47F}
\definecolor{colorE} {HTML}{FF7F7F}

% Layers
\pgfdeclarelayer{dice}
\pgfdeclarelayer{parts}
\pgfdeclarelayer{points}
\pgfsetlayers   {main,dice,parts,points}

% Macros
\newcommand{\die}[2] % name, position
{%
  \node (#1) at #2 {};
  \begin{scope}[shift={#2}]
    \begin{pgfonlayer}{dice}
      \draw[fill=white,rounded corners=0.2cm] (-0.5,-0.5) rectangle (0.5,0.5);
    \end{pgfonlayer}
    \foreach\i in {45,135,225,315}
    {%
      \begin{pgfonlayer}{dice}
        \fill[gray!50] (\i:{0.3*sqrt(2)}) circle (0.15);
      \end{pgfonlayer}
      \begin{pgfonlayer}{points}
        \fill (\i:{0.3*sqrt(2)}) circle (0.1);
      \end{pgfonlayer}
    }
  \end{scope}
}

\newcommand{\twopart}[3] % Node, rotation, color
{%
  \ifthenelse{#2=45 \OR #2=135 \OR #2=225 \OR #2=315}
    {% if the angle is 45 (or equivalent)
      \pgfmathsetmacro\factor{sqrt(2)} % distance between the two points
      \pgfmathsetmacro\delta {0}       % displacement from the origin
    }
    {% for any other angle
      \pgfmathsetmacro\factor{1}
      \pgfmathsetmacro\delta {-0.3}
    }
  \begin{pgfonlayer}{parts}
    \begin{scope}[shift={(#1)}, rotate=#2]
      \fill[#3,rounded corners=0.15cm] (-0.3*\factor-0.15,\delta-0.15) rectangle (0.3*\factor+0.15,\delta+0.15);
    \end{scope}
  \end{pgfonlayer}
}

\newcommand{\threepart}[2] % Node, rotation
{%
  \begin{pgfonlayer}{parts}
    \begin{scope}[shift={(#1)}, rotate=#2]
      \fill[colorD] (-0.3,0.3)++(45:.15) arc (45:180:0.15) --(-0.45,-0.3)
                arc (180:270:0.15) -- (0.3,-0.45) arc (-90:45:0.15) -- cycle;
    \end{scope}
  \end{pgfonlayer}
}

\newcommand{\fourpart}[1] % Node
{%
  \begin{pgfonlayer}{parts}
    \begin{scope}[shift={(#1)}]
      \fill[colorE,rounded corners=0.15cm] (-0.45,-0.45) rectangle (0.45,0.45);
    \end{scope}
  \end{pgfonlayer}
}

\begin{document}
\begin{tikzpicture}
  % DICE
  \die{A1}{( 0, 0)}
  \die{B1}{(-5, 3)}\twopart  {B1}{270}{colorB}
  \die{B2}{(-3, 3)}\twopart  {B2}{ 45}{colorB}
  \die{B3}{(-1, 3)}\twopart  {B3}{  0}{colorB}
  \die{B4}{( 1, 3)}\twopart  {B4}{180}{colorB}
  \die{B5}{( 3, 3)}\twopart  {B5}{135}{colorB}
  \die{B6}{( 5, 3)}\twopart  {B6}{ 90}{colorB}
  \die{C1}{( 0, 9)}\twopart  {C1}{  0}{colorC1}\twopart{C1}{180}{colorC2}
  \die{C2}{(-2, 9)}\twopart  {C2}{ 45}{colorC1}\twopart{C2}{135}{colorC2}
  \die{C3}{( 2, 9)}\twopart  {C3}{270}{colorC1}\twopart{C3}{ 90}{colorC2}
  \die{D1}{(-6,10)}\threepart{D1}{270}
  \die{D2}{(-4,10)}\threepart{D2}{  0}
  \die{D3}{( 4,10)}\threepart{D3}{ 90}
  \die{D4}{( 6,10)}\threepart{D4}{180}
  \die{E1}{( 0,12)}\fourpart {E1}
  % PATHS
  \foreach\i in {1,...,6}
  {% paths from A1
    \path[thick] (A1) edge (B\i);
  }
  \foreach\i in {C3,D1,D2}
  {% paths from B1
    \path[thick] (B1) edge (\i);
  }
  \foreach\i in {C2,D1,D3}
  {% paths from B2
    \path[thick] (B2) edge (\i);
  }
  \foreach\i in {C1,D2,D3}
  {% paths from B3
    \path[thick] (B3) edge (\i);
  }
  \foreach\i in {C1,D1,D4}
  {% paths from B4
    \path[thick] (B4) edge (\i);
  }
  \foreach\i in {C2,D2,D4}
  {% paths from B5
    \path[thick] (B5) edge (\i);
  }
  \foreach\i in {C3,D3,D4}
  {% paths from B6
    \path[thick] (B6) edge (\i);
  }
  \foreach\i in {C1,C2,C3,D1,D2,D3,D4}
  {% paths from E1
    \path[thick] (E1) edge (\i);
  }
\end{tikzpicture}
\end{document}

And, the lattice: 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.