我正在寻找一个列表环境,将元素放置成一个网格(数组、表格……),并对元素进行垂直编号。这个小细节对我来说已经变得非常痛苦。我检查了、、、tasks
和包。但它们都水平处理元素。另一方面,解决方案以不可接受的方式破坏了元素。paralist
tablist
shortlst
multienum
enumerate + multicol
理想情况下,我希望通过破解任务环境来实现这一点,但当然欢迎任何想法。
\documentclass{article}
\usepackage{fullpage}
\usepackage{enumitem,tasks,multicol}
\begin{document}
\def\q{A question}
\def\qq{A long question in this item}
\bf{Grilled (completely aligned) items but horizontally numbered:}
\begin{tasks}(3)
\task \qq
\task \q
\task \qq \dots \qq \dots
\task \q
\task \q
\task \q
\end{tasks}
\bf{Vertically numbered but disordered items:}
\begin{multicols}{3}
\begin{enumerate}[label=\alph*)]
\item \qq
\item \qq \dots \qq \dots
\item \q
\item \q
\item \q
\item \q
\end{enumerate}
\end{multicols}
\end{document}
答案1
通过使用paracol
,将项目按垂直顺序保存,然后按水平顺序读取项目
\documentclass{article}
\usepackage{fullpage}
\usepackage{paracol}
\usepackage{enumitem}
\usepackage{xparse}
\ExplSyntaxOn
\seq_new:N \g_list_seq
\NewDocumentCommand {\myitem} { +m } {
\seq_gput_right:Nn \g_list_seq {#1}
}
\int_new:N \g_count_int
\int_new:N \g_row_int
\int_new:N \g_col_int
\int_new:N \g_ncol_int
\int_new:N \l_temp_int
\cs_new_protected:Nn \calc_var: {
\int_gset:Nn \g_count_int {\seq_count:N \g_list_seq}
\int_gset:Nn \g_row_int {\fp_to_int:n {ceil(\g_count_int / \g_ncol_int)}}
\int_gset:Nn \g_col_int {\fp_to_int:n {ceil(\g_count_int / \g_row_int)}}
}
\cs_new_protected:Nn \print_list: {
\calc_var:
\int_step_variable:nNn {\g_row_int} \l_row_tl {
\int_step_variable:nNn {\g_col_int} \l_col_tl {
\int_set:Nn \l_temp_int {(\l_col_tl - 1) * \g_row_int + \l_row_tl}
\int_compare:nTF
{
\int_mod:nn {\l_col_tl - 1} {\g_ncol_int} = 0
}
{
\switchcolumn[0]*
}
{
\switchcolumn[\int_eval:n {\l_col_tl - 1}]
}
\begin{itemize}[topsep=0pt]
\item[\int_use:N \l_temp_int)]
\seq_item:Nn \g_list_seq {(\l_col_tl - 1) * \g_row_int + \l_row_tl}
\end{itemize}
}
}
}
\NewDocumentEnvironment {paralist} { m } {
\begin{paracol}{#1}
\seq_gclear:N \g_list_seq
\int_gset:Nn \g_ncol_int {#1}
} {
\print_list:
\end{paracol}
}
\ExplSyntaxOff
\begin{document}
\def\q{A question}
\def\qq{A long question in this item}
This is a list.
\begin{paralist}{3}
\myitem{test1\\breakline}
\myitem{test2}
\myitem{test3}
\myitem{test4}
\end{paralist}
This is another list
\begin{paralist}{3}
\myitem{\qq}
\myitem{\qq \dots \qq \dots \qq}
\myitem{\q}
\myitem{\q}
\myitem{\q}
\myitem{\q}
\end{paralist}
\end{document}
答案2
只要您不希望同一“行”中的项目严格对齐,那么您可以使用以下listliketab
包来提供帮助:
\documentclass{article}
\usepackage{fullpage}
\usepackage{enumitem,tasks,multicol}
\usepackage{listliketab, tabularx}
\begin{document}
\def\q{A question}
\def\qq{A long question in this item}
\storestyleof{enumerate}
\begin{listliketab}
\newcounter{tabenum}\setcounter{tabenum}{0}
\newcommand{\tabitem}{\refstepcounter{tabenum}\alph{tabenum})}
\noindent
\begin{tabularx}{0.3\linewidth}[t]{@{}LX}
\tabitem & \qq \\
\tabitem & \qq\dots \qq \dots
\end{tabularx}
\begin{tabularx}{0.3\linewidth}[t]{@{}LX}
\tabitem & \q \\
\tabitem & \qq
\end{tabularx}
\begin{tabularx}{0.3\linewidth}[t]{@{}LX}
\tabitem & \qq\dots \qq \dots \\
\tabitem & \q
\end{tabularx}
\end{listliketab}
\end{document}