\documentclass[a4paper]{article}
\usepackage[inline]{enumitem}
\begin{document}
\begin{itemize*}
\item First point
\item Second point
\item Third point
\end{itemize*}
\end{document}
上面的代码给出了
当我给出时,每行需要两个项目
\begin{itemize*}(2)
\item First point
\item Second point
\item Third point
\end{itemize*}
当我给出时,每行需要三个项目
\begin{itemize*}(3)
\item First point
\item Second point
\item Third point
\end{itemize*}
类似于使用“enumitem”的“任务”
输出类似于
答案1
enumitem
对此实际上并不是必需的(当然,没有更多的背景信息)。xparse
提供了一种使用除 之外的分隔符创建可选参数的简单方法[]
:
\documentclass{article}
\usepackage{xparse}% http://ctan.org/pkg/xparse
\newcounter{itemcntr}
\DeclareDocumentEnvironment{itemize*}{D(){1234}}
{\setcounter{itemcntr}{0}%
\renewcommand{\item}{\stepcounter{itemcntr}%
\ifnum\value{itemcntr}>#1\relax\par\setcounter{itemcntr}{1}\fi%
\textbullet\hspace*{\labelsep}\nobreak}}% \begin{itemize*}
{}% \end{itemize*}
\begin{document}
\begin{itemize}
\item First point
\item Second point
\item Third point
\end{itemize}
\begin{itemize*}
\item First point
\item Second point
\item Third point
\end{itemize*}
\begin{itemize*}(2)
\item First point
\item Second point
\item Third point
\end{itemize*}
\begin{itemize*}(3)
\item First point
\item Second point
\item Third point
\item Fourth point
\item Fifth point
\item Sixth point
\item Seventh point
\item Eighth point
\item Ninth point
\item Tenth point
\end{itemize*}
\end{document}
上面的 MWE 提供了itemize*
采用单个可选参数的选项(<num>)
,将“列表”设置为内联(类似于enumitem
选项[inline]
)。在条目之后,会插入<num>
一个段落分隔符。默认设置为(刚好足够大的数字)...\par
<num>
1234
彻底改造以适应新要求:分项列表分布在页面上,水平对齐。
\documentclass{article}
\usepackage{environ,multido,calc}% http://ctan.org/pkg/{environ,multido,calc}
\makeatletter
% Taken from https://tex.stackexchange.com/a/128318/5764
\newcounter{listcount}% Keep track of \item
\let\olditem\item% Store regular \item macro
\NewEnviron{itemize*}[1][5]{%
\setcounter{listcount}{0}% Start with 0 \items
\g@addto@macro{\BODY}{\item\relax\item}% Used to delimit the items; last item identified by \item\relax\item
\def\item##1\item{% Redefine \item to capture contents
\def\optarg{##1}%
\expandafter\ifx\optarg\relax\else% Last item not reached
\stepcounter{listcount}% Next item being processed
\expandafter\gdef\csname inlineitem@\thelistcount\endcsname{##1}% Store item in control sequence
\expandafter\item% Recursively continue processing items
\fi
}%
\BODY% Process environment (save items)
\setlength{\@tempdima}{\linewidth/#1}% Set length of each \item \parbox; possibly corrent...
\ifnum\value{listcount}<#1\relax\setlength{\@tempdima}{\linewidth/\value{listcount}}\fi%... if needed
\par\noindent% Start new non-indented paragraph
\multido{\i=1+1}{\value{listcount}}{% Insert all items in a \parbox
\parbox[t]{\@tempdima}{\raggedright\hangindent=1.5em\hangafter=1% Paragraph formatting
\makebox[1.5em][r]{\textbullet\space}\strut\csname inlineitem@\i\endcsname\strut}\hspace{0pt}}%
}
\makeatother
\begin{document}
\begin{itemize*}
\item First point
\item Second point
\item Third point
\end{itemize*}
\noindent\hrulefill
\begin{itemize*}[2]
\item First point
\item Second point
\item Third point
\end{itemize*}
\noindent\hrulefill
\begin{itemize*}[3]
\item First point
\item Second point
\item Third point
\item Fourth point
\item Fifth point
\item Sixth point
\item Seventh point
\item Eighth point
\item Ninth point
\item Tenth point
\end{itemize*}
\noindent\hrulefill
\begin{itemize*}[3]
\item First point First point First point First point First point First point First point
\item Second point Second point Second point Second point Second point Second point Second point
\item Third point Third point Third point Third point Third point Third point Third point
\item Fourth point Fourth point Fourth point Fourth point Fourth point Fourth point Fourth point
\item Fifth point Fifth point Fifth point Fifth point Fifth point Fifth point Fifth point
\item Sixth point Sixth point Sixth point Sixth point Sixth point Sixth point Sixth point
\end{itemize*}
\end{document}
第一步是模拟列表,但实际上\item
在宏中捕获每个列表。这可以通过以下帮助来完成:enumerate
自动对环境中的物品进行排序。捕获每个项目后,将按顺序打印\parbox
(使用一些可以调整的默认格式),该格式恰好跨越 的一部分,\linewidth
以便其中正好包含指定的项目数。执行次要检查以确保列表中的项目较少时不遵守默认值。
答案2
建议的语法和你的句子
类似于使用“enumitem”的“任务”
让我相信你已经知道这个tasks
包了。你为什么不使用它呢?
\documentclass{article}
\usepackage[more]{tasks}
\NewTasks[style=itemize]{itemize*}[\item]
\begin{document}
\begin{itemize*}(2)
\item First point
\item Second point
\item Third point
\end{itemize*}
\begin{itemize*}(3)
\item First point
\item Second point
\item Third point
\item Fourth point
\item Fifth point
\item Sixth point
\item Seventh point
\item Eighth point
\item Ninth point
\item Tenth point
\end{itemize*}
\end{document}
如果您想要空心项目符号(如评论中所要求的),您可以将设置textcomp
为\textopenbullet
标签:
\documentclass{article}
\usepackage{tasks}
\usepackage{textcomp}
\NewTasks[
label = \textopenbullet ,
after-item-skip = 0pt plus 1ex ,
label-offset = -1pt
]{itemize*}[\item]
\begin{document}
\begin{itemize*}(2)
\item First point
\item Second point
\item Third point
\end{itemize*}
\begin{itemize*}(3)
\item First point
\item Second point
\item Third point
\item Fourth point
\item Fifth point
\item Sixth point
\item Seventh point
\item Eighth point
\item Ninth point
\item Tenth point
\end{itemize*}
\end{document}
答案3
您可以使用 tablists 包执行枚举环境所需的操作。
然而,shortlst 包允许使用更简单的语法并且可以与 itemize 环境一起工作。
以下是定义 tabitemize 环境的代码,带有一个可选参数,即此环境的列数(默认为 3)。使用 shortlst 的主要优点是,假设每列都有计算出的宽度,如果某个项目的宽度对于一列来说太大,它会自动使用两列。
\documentclass[a11pt, a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[textwidth=15cm]{geometry}
\usepackage{shortlst}
\newenvironment{tabitemize}[1][3]{%
\settowidth{\labelwidth}{\labelitemi}%
\setlength{\leftmargini}{\dimexpr\parindent + \labelwidth + \labelsep\relax}%
\setlength{\shortitemwidth}{\dimexpr\linewidth/#1-\labelwidth-2\labelsep\relax}%
\begin{shortitemize}}%
{\end{shortitemize}}%
\begin{document}
Here is an example:
\begin{tabitemize}[4]
\item First item
\item Second item
\item Third item
\item Fourth item
\item Fifth, sixth and seventh item
\item Eighth item
\end{tabitemize}
\end{document}
不幸的是,shortlst 包不在 MiKTeX 或 TeX Live 发行版中。它可以直接从 CTAN 下载,例如
http://dante.ctan.org/tex-archive/macros/latex/contrib/shortlst.zip