我的 MWE:
\documentclass{article}
\usepackage{amssymb}
\usepackage[ampersand]{easylist}
\usepackage{changepage}
\usepackage{lipsum}
\usepackage{amssymb}
\usepackage[ampersand]{easylist}
\begin{document}
\begin{easylist}
& 1 Align this text vertically
& 20 Align this text vertically
& 300 Align this text vertically
& 4000 Align this text vertically
& 50000 Align this text vertically
\end{easylist}
\end{document}
有可能吗期望输出使用一些简单的命令。\tab
或者类似的东西?
答案1
我会使用tabular
。下面定义了环境Enumtable
、Itemtable
和 ,Desctable
它们的工作方式分别类似于enumerate
、itemize
和description
,但当前的实现实际上不可嵌套,并且不使用全局定义要使用哪些符号等。如果需要这些功能,我可以添加它们。
\documentclass[]{article}
\usepackage{array}
\usepackage{xparse}
\usepackage{collcell}
\makeatletter
\newcolumntype{\ListtableColumn}[1]
{>{\collectcell\Listtable@Item}#1<{\endcollectcell}}
\newcounter{Listtable@counter}
\NewDocumentEnvironment{Enumtable}{ O{} D(){l} m }
{%
\renewcommand*\theListtable@counter{\arabic{Listtable@counter}.}%
\def\Listtable@Item##1%
{%
\stepcounter{Listtable@counter}%
\theListtable@counter
\if\relax\detokenize{##1}\relax
\else
\ ##1%
\fi
}%
\begin{tabular}[#1]{\ListtableColumn{#2} #3}
}
{%
\end{tabular}%
}
\NewDocumentEnvironment{Itemtable}{ O{} D(){l} m }
{%
\def\Listtable@Item##1%
{%
$\bullet$%
\if\relax\detokenize{##1}\relax
\else
\ ##1%
\fi
}%
\begin{tabular}[#1]{\ListtableColumn{#2} #3}
}
{%
\end{tabular}%
}
\NewDocumentEnvironment{Desctable}{ O{} D(){l} m }
{%
\def\Listtable@Item##1%
{%
\if\relax\detokenize{##1}\relax
\else
\textbf{##1}%
\fi
}%
\begin{tabular}[#1]{\ListtableColumn{#2} #3}
}
{%
\end{tabular}%
}
\makeatother
\begin{document}
\begin{Enumtable}{l}
1 & Align this text vertically\\
20 & Align this text vertically\\
300 & Align this text vertically\\
4000 & Align this text vertically\\
50000 & Align this text vertically\\
\end{Enumtable}
\begin{Itemtable}{l}
1 & Align this text vertically\\
20 & Align this text vertically\\
300 & Align this text vertically\\
4000 & Align this text vertically\\
50000 & Align this text vertically\\
\end{Itemtable}
\begin{Desctable}{l}
1 & Align this text vertically\\
20 & Align this text vertically\\
300 & Align this text vertically\\
4000 & Align this text vertically\\
50000 & Align this text vertically\\
\end{Desctable}
\end{document}
输出:
编辑:可嵌套版本。 带有 的可分页功能longtable
似乎不适用于当前代码,带有 的固定宽度功能也不tabularx
适用。 我想如果需要的话,可能需要采用不同的方法。
\documentclass[]{article}
\usepackage{array}
\usepackage{xparse}
\usepackage{collcell}
\usepackage{amssymb}
\usepackage{etoolbox}
\usepackage{duckuments}% just for dummy content
\makeatletter
\newcolumntype{\ListtableColumn}[1]
{>{\collectcell\Listtable@Item}#1<{\endcollectcell}}
\newcounter{Listtable@counter}
\newbox\Listtable@box
\def\Listtable@Item#1{}
\def\Listtable@precounter{}
\renewcommand*\theListtable@counter{}
\newcount\Listtable@layer
\newcommand*\Listtable@itemsep{\hspace{.25cm}}
% extra space if first column has contents in Enumtable or Itemtable
\newcommand*\Listtable@addedspace{\hspace*{.25cm}}
\newcommand*\Listtable@leftskip
{\hspace{\csname Listtable@leftskip@\@alph\Listtable@layer\endcsname}}
\newcommand*\Listtable@leftskip@a{.5cm}
\newcommand*\Listtable@leftskip@b{1cm}
\newcommand*\Listtable@leftskip@c{1.5cm}
\newcommand*\Listtable@leftskip@d{2cm}
\newcommand*\Listtable@item
{\csname Listtable@item@\@alph\Listtable@layer\endcsname}
\newcommand*\Listtable@item@a{$\bullet$}
\newcommand*\Listtable@item@b{$\circ$}
\newcommand*\Listtable@item@c{\begingroup\tiny$\blacksquare$\endgroup}
\newcommand*\Listtable@item@d{\begingroup\tiny$\square$\endgroup}
\newcommand*\Listtable@AfterEnvironment{}
\NewDocumentEnvironment{Listtable}{ O{} m m }%>>>
{%
\begin{tabular}[#1]
{%
@{\Listtable@leftskip} \ListtableColumn{#2} @{\Listtable@itemsep} #3
}%
}
{%
\end{tabular}%
}%<<<
\NewDocumentCommand \Listtable@define { m m m m }%>>>
{%
\NewDocumentEnvironment {#1} { O{} D(){l} m }
{%
\advance\Listtable@layer\@ne
\ifnum\Listtable@layer=\@ne
\par\medskip\noindent
\fi
#2%
\renewcommand\Listtable@Item[1]
{%
#3%
}%
\global\setbox\Listtable@box\hbox\bgroup
\begin{Listtable}[##1]{##2}{##3}%
}
{%
\end{Listtable}%
\egroup
#4
\ifnum\Listtable@layer=\@ne
\expandafter\@firstoftwo
\else
\expandafter\@secondoftwo
\fi
{%
\unhbox\Listtable@box
\par\medskip
}%
{%
\ifhmode\unskip\fi
\gdef\Listtable@AfterEnvironment
{%
\\\noalign
{%
\unhbox\Listtable@box
\gdef\Listtable@AfterEnvironment{}%
\ignorespaces
}%
}%
}%
}%
\AfterEndEnvironment{#1}{\Listtable@AfterEnvironment}%
}%<<<
\Listtable@define{Enumtable}%>>>
{%
\edef\Listtable@savecounter{\the\c@Listtable@counter}%
\edef\Listtable@precounter{\theListtable@counter}%
\setcounter{Listtable@counter}{0}%
\renewcommand*\theListtable@counter
{\Listtable@precounter\arabic{Listtable@counter}.}%
}
{%
\stepcounter{Listtable@counter}%
\theListtable@counter
\if\relax\detokenize{##1}\relax
\else
\Listtable@itemsep ##1\Listtable@addedspace
\fi
}
{%
\setcounter{Listtable@counter}{\Listtable@savecounter}%
}%<<<
\Listtable@define{Itemtable}{}%>>>
{%
\Listtable@item
\if\relax\detokenize{##1}\relax
\else
\Listtable@itemsep ##1\Listtable@addedspace
\fi
}
{}%<<<
\Listtable@define{Desctable}{}%>>>
{%
\if\relax\detokenize{##1}\relax
\else
\textbf{##1}%
\fi
}
{}%<<<
\makeatother
\begin{document}
\blindduck
\begin{Enumtable}{l}
1 & Align this text vertically
\begin{Enumtable}{l}
& second layer test
\begin{Enumtable}{l}
& third layer test
\begin{Enumtable}{l}
& fourth layer test\\
& fourth layer test\\
\end{Enumtable}
& third layer test\\
\end{Enumtable}
& second layer test\\
\end{Enumtable}
20 & Align this text vertically\\
300 & Align this text vertically\\
4000 & Align this text vertically\\
50000 & Align this text vertically\\
\end{Enumtable}
\begin{Itemtable}{l}
1 & Align this text vertically
\begin{Itemtable}{l}
& second layer test
\begin{Itemtable}{l}
& third layer test
\begin{Itemtable}{l}
& fourth layer test\\
& fourth layer test\\
\end{Itemtable}
& third layer test\\
\end{Itemtable}
& second layer test\\
\end{Itemtable}
20 & Align this text vertically\\
300 & Align this text vertically\\
4000 & Align this text vertically\\
50000 & Align this text vertically\\
\end{Itemtable}
\begin{Desctable}{l}
1 & Align this text vertically
\begin{Desctable}{l}
second & layer test
\begin{Desctable}{l}
third & layer test
\begin{Desctable}{l}
fourth & layer test\\
fourth & layer test
\end{Desctable}
third & layer test\\
\end{Desctable}
second & layer test\\
\end{Desctable}
20 & Align this text vertically\\
300 & Align this text vertically\\
4000 & Align this text vertically\\
50000 & Align this text vertically\\
\end{Desctable}
\end{document}