24

I was wandering through the internet and came across http://graphicalcooking.co. An attractive format, and I said to myself, "TikZ can do that!" And so it can. I wrestled with this this morning and have arrived at the following. My only problem is the lines connecting the hexagons in the instructions for the recipe. I cannot think of a way to get the various lines to intersect with each other (at the circled locations) without explicitly computing the distances. It would be nice to have a macro, \connect that would do the work, say, by use of the intersections TikZ library. Any suggestions? I hope I have commented the code sufficiently that there are no mysteries... I've included a couple of examples of what the as-yet fictional \connect macro might do.

\documentclass{article}

%% Compare with http://graphicalcooking.co

\usepackage{xcolor}
\usepackage{tikz}
\usepackage[papersize={5.5in,8.5in},margin=0.5in,bottom=0.75in]{geometry}
\usepackage{xfrac}

\usetikzlibrary{calc,positioning,shapes.geometric,intersections}

\newlength{\minsize}
\newlength{\skipln}

\setlength{\minsize}{1.00in}
\setlength{\skipln}{0.1in}

\def\fr#1/#2 {\sfrac{#1}{#2} }

\tikzset{% Simplify using TikZ pics
    pics/hex/.style n args={4}{% #1= name; #2=color; #3 top in bold; #4 bottom in italics
        code={%
            \node[%
                draw,
                very thick,
                color=#2,
                rounded corners=3pt,
                regular polygon, 
                regular polygon sides=6,
                shape border rotate=90, %% !!
                inner sep=0pt,
                minimum size=\minsize,
                inner sep=0pt,
                align=center
            ] (#1)  at (0,0) {};
            \node[text width=0.95\minsize,align=center]  at (#1)
                {\textbf{\strut#3\strut}\\\emph{\strut#4\strut}};
        }
    }
}

\tikzset{rc/.style = {rounded corners=3pt}}

\begin{document}

\thispagestyle{empty}

\begin{tikzpicture}[]

\pgfmathsetlengthmacro{\movehex}{cos(30) * \minsize} %% (0,0) to *side* of hexagon
\pgfmathsetlengthmacro{\branchln}{(\movehex+\skipln)/2/cos(30)} %% length of line after bend

%%  Create the hexagons
\pic at (0,0) {hex={A}{blue}{Parmesan}{\fr1/4 cup}};
\pic at (\movehex+\skipln,0.0in) {hex={C}{green!70!black}{Lettuce}{\fr1/2 head}};
\pic at (2*\movehex+2*\skipln,0.0in) {hex={D}{orange}{Carrot}{1}};
\pic at (0.5*\movehex+\skipln/2,-\movehex+\skipln/2) {hex={B}{red}{Tomato}{1}};
\pic at (1.5*\movehex+3*\skipln/2,-\movehex+\skipln/2) {hex={E}{purple}{Red Onion}{\fr1/4 }};
\pic at ($(E) + (\movehex+\skipln,0)$) {hex={F}{yellow!80!green}{EVOO}{\fr1/4 cup}};
\pic at ($(F) + (\movehex+\skipln,0)$) {hex={G}{pink}{Red Wine\\Vinegar}{\fr1/8 cup}};

\coordinate (t1) at ($(B)!.5!(E)$);

\path (t1) -- ++(0,-3.5in) coordinate (t2);

%% Draw the connections
%% This would be neater with a macro something like (\connect yet to be defined!):
%% \connect{1.75in}{B.south}{C.south}{0.85in}{Place in bowl} where
%% #1=vertical displacement; #2=source coordinate; #3=coordinate with which to align end of connector
%% #4=vertical displacement for instruction; #5=instruction
%% Would also allow for arbitrary placement of hexagons
\draw[thick] (C.south) -- (t2);
\draw[rc,blue] (B.south) -- ++(0,-1.75in) -- ++(-30:\branchln) node[circle,draw] {};
%% or \connect{-1.75in}{B.south}{C.south}{0.85in}{Place in bowl}
\draw[rc] (E.south) -- ++(0,-1.5in) -- ++(210:\branchln) node[circle,draw] {};
\draw[rc,red] (A.south) -- ++(0,-1.75in) -- ++(-30:\branchln) node[circle,draw] {};
%% or \connect{-1.5in}{A.south}{B.south}{0.5in}{Slice}
\draw[rc] (D.south) -- ++(0,-2.5in) -- ++(210:2*\branchln) node[circle,draw] {};
\draw[rc] (F.south) -- ++(0,-0.25in) -- ++(-30:\branchln) node[circle,draw] {};
\draw[rc] (G.south) -- ++(0,-0.25in) -- ++(210:\branchln) coordinate (i1);
\draw[rc] (i1) -- ++(0,-1in) -- ++(210:4*\branchln) node[circle,draw] {};

%% Ingredient instructions
\node[below=0.85in of C.south,fill=white] {Place in bowl};
\node[below=1.0in of A.south,fill=white] {Grate};
\node[below=0.5in of B.south,fill=white] {Slice};
\node[below=1.0in of E.south,fill=white] {Dice};
\node[below=1.25in of D.south,fill=white] {Chop};
\node[below=0.25in of i1,fill=white] {Mix in blender};
\node[draw,fill=white,rounded corners=3pt] at (t2) {\strut Toss \& Serve};
\end{tikzpicture}

\newpage

\begin{tikzpicture}
\setlength{\skipln}{0.025in}
\pgfmathsetlengthmacro{\movehex}{cos(30) * \minsize}
\pgfmathsetlengthmacro{\branchln}{(\movehex+\skipln)/2/cos(30)}
\pic at (0,-5.25in) {hex={P}{blue}{Parmesan}{}};
\pic at ($(P) + (-60:\movehex+\skipln)$) {hex={Q}{green!70!black}{blue/Z2}{}};
\pic at ($(P) + (\movehex+\skipln,0)$) {hex={R}{orange}{Cheddar\\xxx}{}};
\pic at ($(R) + (\movehex+\skipln,0)$) {hex={S}{purple}{Eggplant\\yyy}{}};
\pic at ($(Q) + (\movehex+\skipln,0)$) {hex={T}{yellow}{Cream\\zzz}{}};

\end{tikzpicture}

\end{document}

enter image description here

8
  • 1
    OT: EVOO = Extra Virgin Olive Oil I guess... is that a common initialism?
    – Thruston
    Feb 22 '18 at 20:53
  • 1
    Yes, it is quite common in foodie literature.
    – sgmoye
    Feb 22 '18 at 20:58
  • 1
    Oh god. Such a receipe would drive me mad ;-) Feb 22 '18 at 21:05
  • 1
    It is not considered, even, I think, by the originators, as any more than an aide-mémoire for very simple recipes, as it lacks substantive instructions. Moreover, complex recipes (cassoulet or boeuf bourguignon) could not be credibly represented in this way. Also, my example is a very rough first-approximation. Still, I can see your point...
    – sgmoye
    Feb 22 '18 at 21:17
  • Chopped carrot... wouldn't grated be easier to eat? And sliced tomato is not very specific; disks or wedges? Feb 22 '18 at 21:17
20

Here is a proposal. I think to have more or less implemented your command except that I replaced the second absolute distance by the fraction of the path. I also like the fact that there is no pineapple in the recipe.

\documentclass{article}

%% Compare with http://graphicalcooking.co
\makeatletter % from https://tex.stackexchange.com/a/412901/121799
\newcommand{\Distance}[3]{% % from https://tex.stackexchange.com/q/56353/121799
\tikz@scan@one@point\pgfutil@firstofone($#1-#2$)\relax  
\pgfmathsetmacro{#3}{veclen(\the\pgf@x,\the\pgf@y)/28.45274}
}
\makeatother 
\newcommand{\Connect}[6][]{%
\node[above=#2 of #4,circle,draw,#1] (y){};
\coordinate (x) at (y-|#3);
\Distance{(x)}{(y)}{\myDst}%\typeout{\myDst}
\ifthenelse {\isempty{#6}}{\draw[rc,#1] (#3) -- ($(x)+(0,0.6*\myDst)$)--(y.center);}{%
\draw[rc,#1] (#3) -- ($(x)+(0,0.6*\myDst)$)  node[pos=#5,fill=white]{#6}-- (y.center);}
}
\usepackage{xifthen}
\usepackage{xcolor}
\usepackage{tikz}
\usepackage[papersize={5.5in,8.5in},margin=0.5in,bottom=0.75in]{geometry}
\usepackage{xfrac}

\usetikzlibrary{calc,positioning,shapes.geometric,intersections,calc}

\newlength{\minsize}
\newlength{\skipln}

\setlength{\minsize}{1.00in}
\setlength{\skipln}{0.1in}

\def\fr#1/#2 {\sfrac{#1}{#2} }

\tikzset{% Simplify using TikZ pics
    pics/hex/.style n args={4}{% #1= name; #2=color; #3 top in bold; #4 bottom in italics
        code={%
            \node[%
                draw,
                very thick,
                color=#2,
                rounded corners=3pt,
                regular polygon, 
                regular polygon sides=6,
                shape border rotate=90, %% !!
                inner sep=0pt,
                minimum size=\minsize,
                inner sep=0pt,
                align=center
            ] (#1)  at (0,0) {};
            \node[text width=0.95\minsize,align=center]  at (#1)
                {\textbf{\strut#3\strut}\\\emph{\strut#4\strut}};
        }
    }
}

\tikzset{rc/.style = {rounded corners=3pt}}



\begin{document}

\thispagestyle{empty}

%% \connect{1.75in}{B.south}{C.south}{0.85in}{Place in bowl} where
%% #1=vertical displacement; #2=source coordinate; #3=coordinate with which to align end of connector
%% #4=vertical displacement for instruction; #5=instruction
%% Would also allow for arbitrary placement of hexagons

\begin{tikzpicture}[]

\pgfmathsetlengthmacro{\movehex}{cos(30) * \minsize} %% (0,0) to *side* of hexagon
\pgfmathsetlengthmacro{\branchln}{(\movehex+\skipln)/2/cos(30)} %% length of line after bend

%%  Create the hexagons
\pic at (0,0) {hex={A}{blue}{Parmesan}{\fr1/4 cup}};
\pic at (\movehex+\skipln,0.0in) {hex={C}{green!70!black}{Lettuce}{\fr1/2 head}};
\pic at (2*\movehex+2*\skipln,0.0in) {hex={D}{orange}{Carrot}{1}};
\pic at (0.5*\movehex+\skipln/2,-\movehex+\skipln/2) {hex={B}{red}{Tomato}{1}};
\pic at (1.5*\movehex+3*\skipln/2,-\movehex+\skipln/2) {hex={E}{purple}{Red Onion}{\fr1/4 }};
\pic at ($(E) + (\movehex+\skipln,0)$) {hex={F}{yellow!80!green}{EVOO}{\fr1/4 cup}};
\pic at ($(F) + (\movehex+\skipln,0)$) {hex={G}{pink}{Red Wine\\Vinegar}{\fr1/8 cup}};

\coordinate (t1) at ($(B)!.5!(E)$);

\path (t1) -- ++(0,-3.5in) coordinate (t2);

\draw[thick] (C.south) -- (t2) node[pos=0.3,fill=white]{Place in bowl};
\node[draw,fill=white,rounded corners=3pt] at (t2) {\strut Toss \& Serve};
\Connect[green]{1.75in}{E.south}{t2.north}{0.7}{Dice} 
\Connect[red]{0.75in}{B.south}{t2.north}{0.3}{Slice} 
\Connect[blue]{0.5in}{A.south}{x}{0.7}{Grate} 
% explanation: the `\Connect` command defines two nodes, x and y,
% which always get overwritten. I am using the x node from the previous
X \Connect here
\Connect[orange]{1.25in}{D.south}{t2.north}{0.7}{Chop}
\coordinate(dummy) at ($(F.south)!0.5!(G.south)+(0,-1in)$);
\Connect{0}{F.south}{dummy}{0.7}{}
\Connect{0}{G.south}{dummy}{0.7}{}
\Connect[thick]{0.25in}{dummy.south}{t2.north}{0.25}{Mix in blender}

\end{tikzpicture}
\end{document}

enter image description here

The main problem, though, is that I really don't like onions. (That's why I connected them with the ugly color.) Could you please leave them out? (Garlic would be soooo much better and healthier!)

4
  • Very nice indeed! I do like pineapple, but not in this salad... Would crispy fried garlic be ok? ;)
    – sgmoye
    Feb 22 '18 at 22:30
  • 3
    Garlic? No way! Have you ever tried Tropea onions?
    – egreg
    Feb 22 '18 at 22:32
  • 1
    @sgmoye I also like pineapples, but not with tomatoes, especially since some freaks put pineapple on pizza. Can you believe it?
    – user121799
    Feb 22 '18 at 22:32
  • 1
    @marmot +1 for I also like the fact that there is no pineapple in the recipe.
    – CarLaTeX
    Feb 23 '18 at 9:17

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.