![拥有自己的物品风格](https://linux22.com/image/321003/%E6%8B%A5%E6%9C%89%E8%87%AA%E5%B7%B1%E7%9A%84%E7%89%A9%E5%93%81%E9%A3%8E%E6%A0%BC.png)
我有一个 LaTeX 文档,其中有 50 个项目enumerate
。我想为这些项目创建一些自己的样式,如下所示:
顶部将是一个带有项目符号的表格,表格下方是项目的内容。
这可能吗?
例子:
\begin{enumerate}
\item Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed felis risus, porttitor id lacus a, placerat fermentum elit. Aenean iaculis auctor magna sed sodales. Donec vitae elementum ligula. Vestibulum porta dui ac sapien vulputate, dignissim rutrum felis sagittis. Proin sit amet pretium lorem. Etiam cursus efficitur volutpat. Morbi id euismod tellus. Praesent sit amet scelerisque eros. Nullam id odio pretium, dignissim orci vitae, placerat dolor. Pellentesque venenatis libero risus, nec fermentum dui vehicula id. Nam consequat quam nisl, id eleifend est malesuada vel. Duis odio mi, lacinia eu consequat eget, sodales vel neque.
\end{enumerate}
答案1
我会创建自己的tabenumerate
环境:
\documentclass{article}
\newcounter{tabenumerate}
\newenvironment{tabenumerate}
{\par\bigskip\setcounter{tabenumerate}{0}%
\renewcommand{\item}{\par\medskip
\noindent\refstepcounter{tabenumerate}%
\begin{tabular}{|l|l|}
\hline
Number of item & \thetabenumerate \\
\hline
\end{tabular}
\par\nobreak
\medskip\noindent
}}{\par\bigskip}
\begin{document}
Some text before \verb|tabenumerate|:
\begin{tabenumerate}
\item First item
\end{tabenumerate}
Some text between \verb|tabenumerate|:
\begin{tabenumerate}
\item First item
\item Second item
\end{tabenumerate}
Some final text.
\end{document}
答案2
这是一个enumitem
解决方案。
\documentclass{article}
\usepackage{enumitem}
\makeatletter
\DeclareRobustCommand{\@boxedlabel}[1]{%
\begin{tabular}{|l|p{5pt}|}
\hline
Number of item & \arabic{#1} \tabularnewline
\hline
\end{tabular}
}
\def\boxedlabel#1{\@boxedlabel{#1}}
\AddEnumerateCounter*{\boxedlabel}{\@boxedlabel}{4}
\makeatother
\begin{document}
\begin{enumerate}[leftmargin=20pt,label={\boxedlabel*},labelwidth=60pt,labelindent=20pt]
\item
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed felis risus, porttitor id lacus a, placerat fermentum elit. Aenean iaculis auctor magna sed sodales. Donec vitae elementum ligula. Vestibulum porta dui ac sapien vulputate, dignissim rutrum felis sagittis. Proin sit amet pretium lorem. Etiam cursus efficitur volutpat. Morbi id euismod tellus. Praesent sit amet scelerisque eros. Nullam id odio pretium, dignissim orci vitae, placerat dolor. Pellentesque venenatis libero risus, nec fermentum dui vehicula id. Nam consequat quam nisl, id eleifend est malesuada vel. Duis odio mi, lacinia eu consequat eget, sodales vel neque.
\item Another one
\end{enumerate}
\end{document}
答案3
这是一个使用enumitem
使用专用tabenum
列表环境提供所需的格式:
\documentclass{article}
\usepackage{enumitem}
\SetLabelAlign{newline}{\makebox[\dimexpr\linewidth-\labelsep][l]{#1}}
\newlist{tabenum}{enumerate}{1}
\setlist[tabenum]{
align=newline,
label={\frame{%
\protect\tabular{|l|l|} Number of item & \arabic*\protect\endtabular}%
},
leftmargin=0pt,
itemindent=\dimexpr\labelwidth+\labelsep
}
\begin{document}
\begin{tabenum}
\item Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed accumsan pulvinar magna, eget suscipit ligula feugiat in. Nam iaculis egestas est sed dictum.
\item Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed accumsan pulvinar magna, eget suscipit ligula feugiat in. Nam iaculis egestas est sed dictum.
\item Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed accumsan pulvinar magna, eget suscipit ligula feugiat in. Nam iaculis egestas est sed dictum.
\end{tabenum}
\end{document}
答案4
解决方案如下enumitem
:
\documentclass{article}
\usepackage{enumitem}%
\newlist{framenum}{enumerate}{1}
\setlist[framenum]{label =\makebox[\linewidth][l]{%
\setlength\fboxsep{-\fboxrule}\fbox{~Number of items\setlength\fboxsep{3pt} \fbox{\,\arabic*\,}}\vrule width0pt depth \topsep height 0pt}, wide=0pt}%
\usepackage{lipsum}
\begin{document}
\lipsum[2]
\begin{framenum}
\item First item
\item Second item
\end{framenum}
\lipsum[3]
\end{document}