10

I would like to imitate the following formatting.

enter image description here

The randomness of the styles should be adjustable by indicating the seed used so that the same diagram is always repeated if necessary.

I would also like to have the same vertical distances between the nodes automatically if possible.

Here is a starting code.

\documentclass{article}

\usepackage{tikz} \usetikzlibrary{shapes, arrows}

\begin{document}

% The styles \tikzset{ block/.style = { rectangle, draw, text width=5em, text centered, minimum height=4em }, connection/.style={ draw, -latex' } }

\begin{tikzpicture}[node distance = 2cm, auto] % Place nodes \node [block] (lint) {Lint}; \node [block, below of = lint] (run) {Run unit and integration tests}; \node [block, below of = run] (build) {Build image}; \node [block, below of = build] (upload) {Upload image to registry}; \node [block, below of = upload, node distance=2.5cm] (update) {Update running service to use new image}; % Draw arrows. \path [connection] (lint) -- (run); \path [connection] (run) -- (build); \path [connection] (build) -- (upload); \path [connection] (upload) -- (update); \end{tikzpicture}

\end{document}

projetmbc
  • 13,315
  • see https://tex.stackexchange.com/q/39296/36296 or https://tex.stackexchange.com/questions/74878/create-xkcd-style-diagram-in-tex for some starting points – samcarter_is_at_topanswers.xyz Dec 28 '22 at 10:41
  • 1
    And \tikzstyle is obsolete. Use \tikzset instead – samcarter_is_at_topanswers.xyz Dec 28 '22 at 10:42
  • An old code copied and pasted by a lazy person... The code in the question has been updated. :-) – projetmbc Dec 28 '22 at 10:49
  • 1
    Re distance between nodes: Use the positioning library and its keys =of instead of of=. [\[1\]](https://tex.stackexchange.com/q/9386), [\[2\]](https://tex.stackexchange.com/a/94396). If you have figured out the randomness and the decorations you will have to do the drawing and the filling separately since they describe different paths: [preaction/postaction`](https://tikz.dev/tikz-actions#sec-15.10). – Qrrbrbirlbel Dec 28 '22 at 11:04
  • 1
    That said, the real challenge will be to setup the decorations. sometimes the sides of the rectangle are straight but drawn separately. Sometimes two of them meet in the corner, some are connected with a big arc. Some are straight, some are tilted slightly. Some sides are interrupted. The calligraphy library might help with the varying line width. – Qrrbrbirlbel Dec 28 '22 at 11:07
  • @Qrrbrbirlbel Do you know how to use calligraphy with the accepted answer? – projetmbc Jan 04 '23 at 14:41
  • 1
    I haven't tested it but instead of drawing the border, you should be able to use the option use pen on it after you've defined a \pen, of course and have loaded the calligraphy library. – Qrrbrbirlbel Jan 06 '23 at 03:27

1 Answers1

19

Well, it's not exactly like your image, but it's a (relatively) easy solution using random steps from the decorations.pathmorphing library. As a preaction the nodes are filled, but with different settings from the way they are drawn. You can adjust those however you like.

The arrows are actually two superimposed arrows (yellow on black) with the second drawn shorter and thinner than the first as a postaction.

I used chains to fix the distance between nodes. Then every join can be set to the connection style.

enter image description here

\documentclass{article}

\usepackage{tikz} \usetikzlibrary{arrows.meta, decorations.pathmorphing, chains}

\begin{document}

% The styles \tikzset{ block/.style = {join, rectangle, draw, line width=2pt, text width=3cm, text centered, minimum height=1.5cm, rounded corners, decorate, decoration={random steps, segment length=6mm, amplitude=1pt}, preaction={fill=#1, rectangle, minimum width=3cm, minimum height=1.5cm, rounded corners, decorate, decoration={random steps, segment length=3mm, amplitude=2mm} } }, connection/.style={ shorten >=2pt, shorten <=2pt, -{Stealth[length=2mm, inset=0, width=4mm, round]}, line width=1.5mm, decorate, decoration={random steps, segment length=4pt, amplitude=.1pt}, postaction={draw, yellow, shorten <=3pt, shorten >=3.5pt, line width=1mm, -{Stealth[length=1.1mm, inset=0, width=2.5mm, round]}} } }

\begin{tikzpicture}[start chain=going below, node distance = 6mm, every join/.style=connection] \pgfmathsetseed{14159} \node [on chain, block=blue!30!green!70!white] (lint) {Lint}; \node [on chain, block=blue!40!green!70!white] (run) {Run unit and integration tests}; \node [on chain, block=blue!50!green!70!white] (build) {Build image}; \node [on chain, block=blue!60!green!70!white] (upload) {Upload image to registry}; \node [on chain, block=blue!70!green!70!white] (update) {Update running service to use new image}; \end{tikzpicture}

\end{document}

Sandy G
  • 42,558