\begin{tabulary} 与 \tabulary 的问题

\begin{tabulary} 与 \tabulary 的问题

我正在开发一些食谱卡的宏,我正在使用包tabulary来限制配料列表的宽度。我尝试了一下,直到找到一些符合我要求的东西,然后把它放进一个\newenvironment。然后我遇到了这个问题这个问题,所以我将\begin{tabulary}\end{tabulary}改为\tabulary\endtabulary

这在 中运行良好\newenvironment,但当我尝试在 之外使用这些命令时\newenvironment,它会默默地忽略表格和文档的其余部分。下面是一个例子。

为什么会这样?\tabulary\endtabulary被允许外出吗\newenvironment

\documentclass{article}

\usepackage{tabulary}

% Ingredients table environment
\newenvironment{ingredients}[0]{
\noindent\textbf{\textsf{Ingredients}}

\noindent
\tabulary{0.5\textwidth}{RL}}{
\endtabulary}

% Create an ingredient in the ingredients table
% First arg is the amount
% Second arg is the ingredient name
\newcommand{\ingredient}[2]{#1 & #2 \\}

\begin{document}

% Version 1: \begin{tabulary}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\noindent\textbf{\textsf{Ingredients}}

\noindent
\begin{tabulary}{0.5\textwidth}{RL}
\ingredient{1 can (10-3/4 oz)}{Condensed cream of chicken soup, undiluted}
\ingredient{1 cup}{Sour cream}
\ingredient{1}{Small onion, finely chopped}
\ingredient{1/4 cup}{Butter}
\ingredient{3/4 tsp}{Salt}
\ingredient{1/4 tsp}{Pepper}
\ingredient{1 package}{Frozen, cubed hash brown potatoes, thawed}
\ingredient{2 cups}{Shredded cheddar cheese}
\end{tabulary}

% Version 2: \tabulary in an environment
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\begin{ingredients}
\ingredient{1 can (10-3/4 oz)}{Condensed cream of chicken soup, undiluted}
\ingredient{1 cup}{Sour cream}
\ingredient{1}{Small onion, finely chopped}
\ingredient{1/4 cup}{Butter}
\ingredient{3/4 tsp}{Salt}
\ingredient{1/4 tsp}{Pepper}
\ingredient{1 package}{Frozen, cubed hash brown potatoes, thawed}
\ingredient{2 cups}{Shredded cheddar cheese}
\end{ingredients}

% Version 3: \tabulary on its own
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\noindent\textbf{\textsf{Ingredients}}

\noindent
\tabulary{0.5\textwidth}{RL}

\ingredient{1 can (10-3/4 oz)}{Condensed cream of chicken soup, undiluted}
\ingredient{1 cup}{Sour cream}
\ingredient{1}{Small onion, finely chopped}
\ingredient{1/4 cup}{Butter}
\ingredient{3/4 tsp}{Salt}
\ingredient{1/4 tsp}{Pepper}
\ingredient{1 package}{Frozen, cubed hash brown potatoes, thawed}
\ingredient{2 cups}{Shredded cheddar cheese}

\endtabulary

This paragraph will not appear.

\end{document}

示例 PDF

答案1

与许多其他环境一样,tabulary需要将所有文本抓取到最终环境,以便它可以进行试运行来找到列宽。

\tabulary形式(如记录所述)是用于另一个环境定义的特殊构造,它允许tabulary检测外部环境名称,以便它可以抓取在文档中\end{ingredients} 没有理由使用的内容\tabulary,并且正如您所观察到的,它不起作用。

相关内容