5

I'm trying to write a command to display a list of ingredients in a cookbook. What I currently have is a command that generates a 4 column tabularx where an input

\ingredients{
    \ing{1 1/2}{pounds sirloin tip or chuck roast, cubed}
    \ing{1}{teaspoon dry thyme}
    \ing{3-4}{carrots}
    \ing{}{Oil}
    \ing{}{Salt and pepper}
    \ing{3}{cups chicken broth}
    \ing{1/2-1}{onion}
    \ing{3}{cups beef broth}
    \ing{2}{teaspoons soy sauce}
    \ing{2/3}{cup pearled barley (not quick cook)}
    \ing{2}{cloves garlic}
    \ing{1}{tablespoon tomato paste}
}

generates the output ingredient list in table where each \ing fills in 2 columns and it works its way down. The problem that I'm having arises when an ingredient is more than one line long, in which case it leaves a gap on the other side.

My first though for how to fix this is to use multicols and put a 2-column table in each, but I don't know how to split the ingredients so that the two columns have roughly equal height other than naively putting half in one column and the other half in the other.

Does anyone know how I might be able to determine where the best split is to get even length lists? Or recommend any better way to display the items in the first place?

Here is a MWE of what I'm currently using:

\documentclass{article}
\usepackage{tabularx}
\usepackage{xparse}
\usepackage{etoolbox}
\usepackage{framed}
\usepackage[bottom=1in, right=1.5in]{geometry}


\makeatletter

\newtoggle{evenrow}
\def\@ingredients{}

\NewDocumentCommand{\ingredients}{m}{
    \g@addto@macro\@ingredients{%
        \global\toggletrue{evenrow}%
        #1
    }
}

\newcommand{\ing}[2]{%
    \iftoggle{evenrow}{\global\togglefalse{evenrow}}{\global\toggletrue{evenrow}}%
    #1 & #2
    \iftoggle{evenrow}{\\}{&}
}

\newcommand{\maketable}{
    \begin{framed}%
        \begin{tabularx}{\textwidth}{@{}r@{ }Xr@{ }X@{}}%
            \@ingredients
        \end{tabularx}%
    \end{framed}
}

\makeatother


\begin{document}
    \ingredients{
        \ing{1 1/2}{pounds sirloin tip or chuck roast, cubed}
        \ing{1}{teaspoon dry thyme}
        \ing{3-4}{carrots}
        \ing{}{Oil}
        \ing{}{Salt and pepper}
        \ing{3}{cups chicken broth}
        \ing{1/2-1}{onion}
        \ing{3}{cups beef broth}
        \ing{2}{teaspoons soy sauce}
        \ing{2/3}{cup pearled barley (not quick cook)}
        \ing{2}{cloves garlic}
        \ing{1}{tablespoon tomato paste}
    }
    \maketable
\end{document}
5
  • 2
    Use multicols rather than \twocolumn. And please post code for a complete but small example we can compile to help you.
    – cfr
    Commented Jun 14 at 3:49
  • Updated to reflect using multicols and to add a MWE
    – corndog
    Commented Jun 14 at 6:10
  • Why don't you use a list rather than a table? Then you can just let multicols balance the columns.
    – cfr
    Commented Jun 14 at 6:36
  • I was using a table to right-align the numbers and left-align the text
    – corndog
    Commented Jun 14 at 6:39
  • Yes, but you can right-align the labels and left-align the text using description.
    – cfr
    Commented Jun 14 at 7:00

1 Answer 1

6

I would implement as an environment, but I've kept your syntax. It needs tidying. Proof of concept:

2 column ingredients

\documentclass{article}
\usepackage{calc}
\usepackage[bottom=1in, right=1.5in]{geometry}
\usepackage{enumitem}
\usepackage{multicol}
\newlist{ingr}{description}{1}
\setlist[ingr]{style=multiline,font=\normalfont,leftmargin=3em,align=right,itemsep=0.25\smallskipamount}
\NewDocumentCommand \ingredients {+m}
{%
  \noindent
  \fbox{%
    \parbox{.9\linewidth}{%
      \begin{multicols}{2}
      \begin{ingr}
        #1
      \end{ingr}%
      \end{multicols}%
    }%
  }%
}
\NewDocumentCommand \ing {+m+m}
{%
  \item[#1]#2
}

\begin{document}
\ingredients{%
  \ing{1 1/2}{pounds sirloin tip or chuck roast, cubed}
  \ing{1}{teaspoon dry thyme}
  \ing{3-4}{carrots}
  \ing{}{Oil}
  \ing{}{Salt and pepper}
  \ing{3}{cups chicken broth}
  \ing{1/2-1}{onion}
  \ing{3}{cups beef broth}
  \ing{2}{teaspoons soy sauce}
  \ing{2/3}{cup pearled barley (not quick cook)}
  \ing{2}{cloves garlic}
  \ing{1}{tablespoon tomato paste}%
}
\end{document}
2
  • This is perfect. I never thought to use the numbers as labels, that's very clever
    – corndog
    Commented Jun 14 at 7:20
  • @corndog you might want a different style than multiline. enumitem provides several, but I can't really visualise the descriptions very well, so you may want to experiment if this doesn't work as you want ;).
    – cfr
    Commented Jun 14 at 7:39

You must log in to answer this question.

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