我如何制作一个看起来像枚举列表的表格?

我如何制作一个看起来像枚举列表的表格?

我正在尝试创建一个模拟枚举列表的表格。这个想法是,第一列应该具有与枚举标签完全相同的水平填充和缩进。下面是我目前所拥有的。我试图根据列表环境的标准度量(、等)来制定解决方案\leftmargin\labelsep它几乎可以正常工作,但由于某种原因,表格后面的文本被分成了自己的段落。有人知道为什么会这样吗?我也希望得到有关如何简化我的解决方案的提示。

\documentclass{article}

\usepackage[showframe, a5paper]{geometry}
\usepackage{array}

\begin{document}
Ut dapibus elementum lorem ut rutrum. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed non nulla dignissim, dignissim nunc ac, auctor magna.
\begingroup
    \list{}{\leftmargin 0pt}\item \relax
        \begin{tabular}{
            @{}                   % left padding
            >{\raggedleft}        % right-align column
            p{\labelwidth}        % column width
            @{\hspace{\labelsep}} % right pading
            l
            l
            l
        }
            1. & A & sit & amet \\
            2. & B & . & tincidunt \\
            3. & C & nulla & $f(x) = \sqrt[3]{x}$
        %   ^^^ I want this column to look exactly like the "label column" of a list
        \end{tabular}
    \endlist
\endgroup % the following text will not stick to the previous paragraph
Duis quam sem, finibus in nisi non, facilisis blandit magna. Mauris a arcu et est elementum pulvinar. Curabitur eros sem, vehicula nec augue nec, accumsan luctus turpis.
\begin{enumerate}
\item A
\item B
\end{enumerate}
Mauris a arcu et est elementum pulvinar. Curabitur eros sem, vehicula nec augue nec, accumsan luctus turpis. Curabitur id mauris semper, interdum ligula ac, sagittis velit.

\end{document}

XeLaTeX 输出

顺便说一下,外部环境基于引用环境的实现,我经常看到它被推荐作为自定义列表或类似引用的环境的起点:

$ latexdef quote

\quote:
\long macro:->\list {}{\rightmargin \leftmargin }\item \relax 

$ latexdef endquote

\endquote:
\long macro:->\endlist 

答案1

listliketab包是为此而制作的:

\documentclass{article}
\usepackage{array}
\usepackage{listliketab}

\begin{document}
Ut dapibus elementum lorem ut rutrum. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed non nulla dignissim, dignissim nunc ac, auctor magna.

\storestyleof{enumerate}
    \begin{listliketab}
    \newcounter{tabenum}\setcounter{tabenum}{0}
    \newcommand{\tabitem}{\addtocounter{tabenum}{1}\thetabenum.}
        \begin{tabular}{@{\hspace*{-0.67em}}L l l l@{}}
          \tabitem & A & sit & amet \\
          \tabitem & B & . & tincidunt \\
          \tabitem & C & nulla & $f(x) = \sqrt[3]{x}$
        \end{tabular}
        \end{listliketab}

Duis quam sem, finibus in nisi non, facilisis blandit magna. Mauris a arcu et est elementum pulvinar. Curabitur eros sem, vehicula nec augue nec, accumsan luctus turpis.
    \begin{enumerate}
    \item A
    \item B
    \end{enumerate}
Mauris a arcu et est elementum pulvinar. Curabitur eros sem, vehicula nec augue nec, accumsan luctus turpis. Curabitur id mauris semper, interdum ligula ac, sagittis velit.

\end{document} 

在此处输入图片描述

编辑\InsertBoxC:如果我很好地理解了您的最后一个要求,您可以使用以下命令从纯 TeX 宏包中获取所需的内容insbox

\documentclass{article}
\usepackage{array}
\usepackage{listliketab}
\usepackage{insbox}

\begin{document}

Ut dapibus elementum lorem ut rutrum. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed non nulla dignissim, dignissim nunc ac, auctor magna. %Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed non nulla dignissim, dignissim nunc ac, auctor magna.%
\InsertBoxC{\parbox{\textwidth}{\vspace*{-\baselineskip}\storestyleof{enumerate}%
    \begin{listliketab}
    \newcounter{tabenum}\setcounter{tabenum}{0}
    \newcommand{\tabitem}{\addtocounter{tabenum}{1}\thetabenum.}
        \begin{tabular}{@{\hspace*{-0.67em}}L l l l@{}}
          \tabitem & A & sit & amet \\
          \tabitem & B & . & tincidunt \\
          \tabitem & C & nulla & $f(x) = √[3]{x}$
        \end{tabular}\vspace{-\baselineskip}
        \end{listliketab}}}%
%
Duis quam sem, finibus in nisi non, facilisis blandit magna. Mauris a arcu et est elementum pulvinar. Curabitur eros sem, vehicula nec augue nec, accumsan luctus turpis.
    \begin{enumerate}
    \item A
    \item B
    \end{enumerate}
Mauris a arcu et est elementum pulvinar. Curabitur eros sem, vehicula nec augue nec, accumsan luctus turpis. Curabitur id mauris semper, interdum ligula ac, sagittis velit.

\end{document} 

在此处输入图片描述

答案2

只需将环境中定义垂直空间的所有长度设置list0pt。顺便问一下,为什么要一起使用\begingroup\list\endlist\endgroup而不是通常的\begin{list}和 ,\end{list}后者具有相同的效果,但 LaTeX 代码更好?

编辑list:实际上,如果将其放置\par\noindent在表格之前和之后,您就可以摆脱环境。

\documentclass{article}

\usepackage[showframe, a5paper]{geometry}
\usepackage{array}

\begin{document}
Ut dapibus elementum lorem ut rutrum. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed non nulla dignissim, dignissim nunc ac, auctor magna.

   \begin{list}{}{%
       \setlength\leftmargin{0pt}\setlength{\topsep}{0pt}
       \setlength{\itemsep}{0pt}\setlength\partopsep{0pt}
       \setlength{\parskip}{0pt}\setlength\parsep{0pt}
     }\item
     \begin{tabular}{
       @{}                   % left padding
       >{\raggedleft}        % right-align column
       p{\labelwidth}        % column width
       @{\hspace{\labelsep}} % right pading
       l
       l
       l
       }
       1. & A & sit & amet \\
       2. & B & . & tincidunt \\
       3. & C & nulla & $f(x) = \sqrt[3]{x}$ \\
       % ^^^ I want this column to look exactly like the "label column" of a list
     \end{tabular}
  \end{list}
Duis quam sem, finibus in nisi non, facilisis blandit magna. Mauris a arcu et est elementum pulvinar. Curabitur eros sem, vehicula nec augue nec, accumsan luctus turpis.

\par\noindent
    \begin{tabular}{
       @{}                   % left padding
       >{\raggedleft}        % right-align column
       p{\labelwidth}        % column width
       @{\hspace{\labelsep}} % right pading
       l
       l
       l
       }
       1. & A & sit & amet \\
       2. & B & . & tincidunt \\
       3. & C & nulla & $f(x) = \sqrt[3]{x}$ \\
       % ^^^ I want this column to look exactly like the "label column" of a list
     \end{tabular}
\par\noindent
Duis quam sem, finibus in nisi non, facilisis blandit magna. Mauris a arcu et est elementum pulvinar. Curabitur eros sem, vehicula nec augue nec, accumsan luctus turpis.
\begin{enumerate}
\item A
\item B
\end{enumerate}
Mauris a arcu et est elementum pulvinar. Curabitur eros sem, vehicula nec augue nec, accumsan luctus turpis. Curabitur id mauris semper, interdum ligula ac, sagittis velit.

\end{document}

在此处输入图片描述

答案3

我建议使用实际enumerate环境。要获取列,请使用包。您可以在和tabto中指定制表符值。可以以相同的方式添加更多列。\za\zb

\documentclass{article}
\usepackage{enumitem,tabto}
\newcommand\za{\tabto*{.3in}}
\newcommand\zb{\tabto*{.8in}}
\begin{document}
\begin{enumerate}
            \item A\za sit   \zb amet
            \item B\za .     \zb tincidunt
            \item C\za nulla \zb $f(x) = \sqrt[3]{x}$
\end{enumerate}
\end{document}

在此处输入图片描述


补充

为了响应 OP 希望列自动调整到内容的愿望,我实现了一个版本,将列制表符写入文件.abc,然后使用它们读回。最多可能需要 3 次编译才能完全解析列宽。如果列内容或填充缩小,\@starttoc{abc}有时可能还需要删除.aux和文件并重新编译。.abc

MWE 是为 5 列表格设置的。 的值\padding定义了列间间隙。

\documentclass{article}
\usepackage{enumitem,tabto}
\newlength\zaval   \newlength\zbval
\newlength\zcval   \newlength\zdval
\newlength\padding
\setlength\padding{1em}
\newcommand\z[1]{\zaux#1\relax}
\def\zaux#1&#2&#3&#4&#5\relax{\za{#1}\zb{#2}\zc{#3}\zd{#4}#5}
\newcommand\za[1]{\zcheck{#1}{0pt}   {\zaval}}
\newcommand\zb[1]{\zcheck{#1}{\zaval}{\zbval}}
\newcommand\zc[1]{\zcheck{#1}{\zbval}{\zcval}}
\newcommand\zd[1]{\zcheck{#1}{\zcval}{\zdval}}
\newcommand\zcheck[3]{#1\sbox0{\ignorespaces#1\unskip\kern\padding}
  \ifdim\dimexpr#2+\wd0>#3\relax
  \global#3=\dimexpr#2+\wd0\relax\fi
  \tabto*{#3}}
\makeatletter
\AtBeginDocument{\@starttoc{abc}}
\makeatother
\AtEndDocument{%
\addtocontents{abc}
  {\noexpand\global\noexpand\zaval=\the\zaval\noexpand\relax}
\addtocontents{abc}
  {\noexpand\global\noexpand\zbval=\the\zbval\noexpand\relax}
\addtocontents{abc}
  {\noexpand\global\noexpand\zcval=\the\zcval\noexpand\relax}
\addtocontents{abc}
  {\noexpand\global\noexpand\zdval=\the\zdval\noexpand\relax}
}
\begin{document}
\begin{enumerate}
  \item \z{A  & situation& amet                & hi mom     & Done}
  \item \z{B  & .        & tincidunt           & Boo!       & right}
  \item \z{bcC& nulla    & $f(x) = \sqrt[3]{x}$& Tsk, Tsk...& now.}
\end{enumerate}
\end{document}

在此处输入图片描述

对于这些特定数据,.abc文件最终为

\global \zaval =27.50005pt\relax 
\global \zbval =75.88905pt\relax 
\global \zcval =133.36137pt\relax 
\global \zdval =190.69481pt\relax 

相关内容