我正在尝试创建一个食谱汇总表,就像这一页使用 latex。我的最终目标是能够将我的食谱集写成库克朗并使用 python 脚本将它们显示为这些图表,但我仍在使用 latex 制作初始图表。
这些 答案是我在研究过程中能找到的最接近的,但都没有展示如何将食谱结构转换成图表。可能还有其他一些我忽略的问题,因为该网站的作者手动格式化菜谱摘要。
我对 latex 还很陌生,希望我忽略了一些显而易见的东西,但我没有找到一种方法来描述我想要的结构,而不是手动格式化输出。我使用 struktex 得到了很多方法,因为 cookingforengineers.com 图表看起来很像一个Nassi-Shneiderman 图,但我仍然对输出不满意。
最小工作示例:
\documentclass{article}
\usepackage{struktex}
\begin{document}
\begin{struktogramm}(100,50)
\assign{Cool and Cut}
\ifthenelse[20]{1}{1}{350°F for 20 min}{Crust}{Filling}
\sub{350°F for 20 min}
\sub{refrigerate for 30 min.}
\sub{line 9x13" pan}
\ifthenelse[10]{1}{1}{Process}{}{}
\ifthenelse[10]{1}{1}{Mix}{}{}
\change
\ifend
\assign{Flour}
\assign{Sugar}
\assign{Cornstarch}
\assign{Salt}
\change
\assign{Butter}
\ifend
\change
\ifthenelse[30]{1}{1}{Mix}{}{}
\assign{Lemon Zest}
\assign{Lemon Juice}
\assign{Whole Milk}
\change
\ifthenelse[10]{1}{1}{Whisk}{}{}
\assign{Eggs}
\assign{Sugar}
\change
\assign{Flour}
\assign{Salt}
\ifend
\ifend
\ifend
\end{struktogramm}
\end{document}
我想要的是:
- 表格流程图布局
- 让菜谱结构一目了然
- 图表布局遵循菜谱顺序(即先用原料)
我已经使用上述代码解决了问题 1 和 2,但我不确定如何获得问题 3。我怀疑我需要完全放弃 struktex 包,但我还没有找到更好的方法来获得我想要的布局,而无需诉诸手动格式化。
为什么我的例子不符合我的需要:
- 图表布局与菜谱顺序相反
- 配方成分长度的差异会留下空隙(例如“黄油”和“全脂牛奶”)
- 垂直布局限制了成分的长度,以达到合理的页面宽度
答案1
问候并欢迎来到 tex.stackexchange!
我也一直在看 Michael Chu 的表格配方符号格式已经存在了相当长一段时间。这似乎是一种揭示食谱结构方面的有趣方式。值得注意的是,Chu 先生已决定尝试为该格式申请专利(尽管“专利申请中”的注释已在他的网站上存在了 15 年多):我找不到该申请,所以我不知道新颖且非显而易见的过程(美国专利商标局的部分特征是专利) 均受专利保护。据 Chu 先生介绍,他先用 HTML 编写原图,然后用 Illustrator 完成最终效果。
从一开始,我就觉得 TeX 可以胜任这项工作,而且在 Ti 的帮助下它也可以做到钾Z. 以下代码相当适合我的目的。我对代码进行了相当好的注释(我承认,注释有些冗长)。
\documentclass[border=5mm]{standalone}
\usepackage{fontspec,xcolor,tikz,xparse,keyval}
\usetikzlibrary{calc,positioning,backgrounds}
\newcounter{stepB}
\newlength{\stagewd}
\newlength{\columnoffset}
\newcounter{stage}
\newcounter{ingnum}
\newcounter{ingnumtmp}
\newif\ifshownums
%% color defaults:
\colorlet{titlefill}{orange!30}
\colorlet{ingredfill}{yellow!80!red!20}
\colorlet{taskfill}{cyan!20}
\colorlet{stagebackground}{gray!80!red!20}
\makeatletter %% keyval
\define@key{engin}{shownums}[true]{\csname shownums#1\endcsname}
\define@key{engin}{titlefill}{\colorlet{titlefill}{#1}}
\define@key{engin}{ingredfill}{\colorlet{ingredfill}{#1}}
\define@key{engin}{taskfill}{\colorlet{taskfill}{#1}}
\define@key{engin}{stagebackground}{\colorlet{stagebackground}{#1}}
\makeatother
%% Dissect ingredient listing
\NewDocumentCommand{\ingredlist}{ >{\SplitList{;}}m }{\par\ProcessList{#1}{\fooaux}}
\NewDocumentCommand{\fooaux}{m} {\fooauxa{#1}}
\NewDocumentCommand{\fooauxa}{m}{% Format ingredients, each in its own node
\stepcounter{ingnum}
\stepcounter{ingnumtmp}
\ifnum \theingnumtmp=0 % nodes containing indidual ingredients, first ingredient
\node[boxy] (A1) {\strut#1\strut};
\else % next ingredients
\node[boxy,below = 0pt of A\theingnumtmp] (A\theingnum) {\strut#1\strut};
\fi
\ifshownums % show ingredient numbers.
\node[left,anchor=south east] at (A\theingnum.south east) {\tiny I-\theingnum};%
\fi
}
\NewDocumentEnvironment{recipe}{ O{} m m }{% #1 Ingredients, csv; #2 optional title
\setlength{\stagewd}{0in}%
\setlength{\columnoffset}{0pt}%
\setcounter{ingnum}{0}%
\setcounter{ingnumtmp}{-1}%
\setkeys{engin}{#1}%
\noindent
\begin{tikzpicture}[node distance=0pt]
\tikzset{boxy/.style={draw,text width=1.35in,outer sep=0pt,
fill=ingredfill,font=\bfseries\hangindent1.25em}}%
\ingredlist{#3}%
% tasks and stages follow
}{% finish up and decorate
\ifnum\thestage=0 % avoid error if no stages, just listing ingredients
\else
\draw[ultra thick,purple] (A1.north east) -- (A\theingnum.south east);
\ifnum\thestage=1 % Avoid error if only one stage
\else
\foreach \nn in {2,...,\thestage} {\draw[very thick] (A1.north -| S\nn) --
(S\nn |- A\theingnum.south);}
\fi
\ifshownums % show stage designation
\foreach\nnn in {1,...,\thestage}
\node[font=\bfseries\tiny,inner sep=0pt,below right =1pt and 1.5pt of S\nnn]
{\romannumeral\nnn};% stages marked with Alpha
\fi
\draw[ultra thick,fill=titlefill]% Title
(A1.north west) rectangle node[font=\huge\bfseries]{\itshape#2}
($(B\thestepB |- S1) + (0,2.5*\baselineskip)$);
\begin{scope}[on background layer]% tasks background
\fill[stagebackground] (S1) rectangle (A\theingnum.south west -| B\thestepB);
\foreach \ni in {1,...,\theingnum} \draw (A\ni.south west) --
(A\ni.south -| S\thestage);
\end{scope}
\draw[ultra thick] (A1.north west) rectangle
(A\theingnum.south west -| B\thestepB);
\fi
\end{tikzpicture}%
}
%% 1[width, for new column -- use \stagewd to repeat or alter]; 2start; 3end;4 text; *note
%% Note that the fourth argument is delimited by `;' which has nothing to do with TikZ
\NewDocumentCommand{\tk}{o u{ } u{ } u{;} s}{%
\IfBooleanF{#5}{\stepcounter{stepB}}%
\IfNoValueF{#1}{%There is a column width specified
\stepcounter{stage}%
\setlength{\columnoffset}{\dimexpr\columnoffset + \stagewd\relax}%
\setlength{\stagewd}{\dimexpr#1\relax}% Timing! Argument can be expression
\coordinate (S\thestage) at ($(A1.north east) + (\columnoffset,0)$);% Stage
\coordinate (SH\thestage) at ($(A1.north east) + (\columnoffset+\stagewd/2,0)$);% Stage mid
}%
\draw[fill=taskfill] (S\thestage |- A#2.north east)% UL
rectangle node[text width = \stagewd-6pt,align=center]% node
{\IfBooleanT{#5}{\itshape\bfseries\color{red}}\strut#4\strut} % content
($(S\thestage |- A#3.south east) + (\stagewd,0in)$) coordinate (B\thestepB); % LR
\IfBooleanF{#5}{\ifshownums\node[font=\tiny,above left=0pt and 0pt of B\thestepB]
{\thestepB};\fi}%
}
\setmainfont{STIX Two Text}
\begin{document}
% On the left, are the ingredients in the order used. On the right, the method
% is divided into columns, each a *stage* in the process; each stage (column) contains tasks.
% The recipe environment takes three arguments:
% #1 Optional keyval choices:
% <shownums> or <shownums=true> shows ingredient, stage and task numbers
% omitting <shownums> or <shownums=false> hides the numbers
% Background colors for the title, stages and tasks can be assigned using
% <titlefill>, <ingredfill>, <taskfill>, and <stagebackground>
% #2 Title
% #3 A comma-separated list of ingredients; a textual comma has to be enclosed in braces {}
% A good starting point would be to initiate the recipe environment with only
% the ingredients, using [shownums]. This will show the ingredient row numbers
% making it easier to indicate the tasks.
% The \tk macro is used for the stages and tasks
% An optional argument to \tk (eg [1in]) initiates a new stage column
% and specifies the width of the current stage column.
% Manner of use: \tk[<dimen>]<from row> <to row> <ingredient>,
%% -->>[...] starts new column -- can contain expression; use \stagewd only after first stage
% or: \tk <from row> <to row> <ingredient>, -->>continues with task in stage column
% Optional argument to recipe is for keyval
\thispagestyle{empty}
\centering
\begin{recipe}[shownums,stagebackground=red!10]{Toll House Cookies}{%
%% the ingredients, ;-separated
1 cup butter;
¾ cup granulated sugar;
¾ cup brown sugar;
1 tsp. vanilla;
2 large eggs;
2¾ cup flour;
1 tsp baking soda;
½ tsp. salt;
2 cups chocolate chips;
1 cup nuts, chopped}
%% |=====8><-----| %% the method
\tk[1in]1 1 Soften;
\tk 5 5 Room temp.;*
\tk 6 8 Combine;
\tk[\stagewd-0.25in]1 4 Beat until smooth;
\tk[1in]1 5 Beat in one egg at a time;
\tk[1in]1 8 Gradually beat in flour mixture;
\tk[1in]1 10 Form into $\approx$1-inch balls and place on baking sheet;
\tk[1in]1 10 Bake at 375°F for 10 minutes;
\end{recipe}
\end{document}
相同之处shownums=false
: