![创建一个枚举列表,每个项目后都带有点填充](https://linux22.com/image/450505/%E5%88%9B%E5%BB%BA%E4%B8%80%E4%B8%AA%E6%9E%9A%E4%B8%BE%E5%88%97%E8%A1%A8%EF%BC%8C%E6%AF%8F%E4%B8%AA%E9%A1%B9%E7%9B%AE%E5%90%8E%E9%83%BD%E5%B8%A6%E6%9C%89%E7%82%B9%E5%A1%AB%E5%85%85.png)
我正在尝试使用\dotfill
后每件物品都创建一个“假目录”。但我现在得到的是点前该项目,而不是之后。
\usepackage{enumitem}
\newlist{faketoc}{enumerate}{10}
\setlist[faketoc]{label*=\textbf{.\arabic*}} \setlist[faketoc,1]{label=\textbf{\arabic*}}
\let\olditem\item
\renewcommand{\item}{\olditem\dotfill}
\begin{faketoc}
\item One
\begin{faketoc}
\item Two
\item Three
\begin{faketoc}
\item Two
\item Three
\item Four
\end{faketoc}
\item Four
\end{faketoc}
\item Five
\item Six
\end{faketoc}
这导致以下输出
我想要实现的是
1 One ............................
1.1 Two ........................
如果有人能帮助我我会很高兴。
答案1
如果你不介意写成\item{One}
,\item One
那么重新定义\item
为
\renewcommand\item[1]{\olditem #1\dotfill}
正如@Lupino 指出的那样,这会干扰所有枚举列表,因此此更改仅应针对环境激活fakedoc
。
\let\faketocolditem\item
\newcommand\faketocitem[1]{\faketocolditem#1\dotfill}%
\AddToHook{env/faketoc/begin}{\let\item\faketocitem}
\documentclass{article}
\usepackage{enumitem}
\newlist{faketoc}{enumerate}{10}
\setlist[faketoc]{label*=\textbf{.\arabic*}} \setlist[faketoc,1]{label=\textbf{\arabic*}}
\let\faketocolditem\item
\newcommand\faketocitem[1]{\faketocolditem#1\dotfill}%
\AddToHook{env/faketoc/begin}{\let\item\faketocitem}
\begin{document}
\begin{faketoc}
\item{One}
\begin{faketoc}
\item{Two}
\item{Three}
\begin{faketoc}
\item{Two}
\item{Three}
\item{Four}
\end{faketoc}
\item{Four}
\end{faketoc}
\item{Five}
\item{Six}
\end{faketoc}
\end{document}
答案2
您可以点击\item
并\end{faketoc}
插入\dotfill
,然后再转到下一个项目。以下操作可实现此目的(未经广泛测试)。
\documentclass{article}
\usepackage{enumitem}
\newlist{faketocaux}{enumerate}{10}
\setlist[faketocaux]{label*=\textbf{.\arabic*}}
\setlist[faketocaux,1]{label=\textbf{\arabic*}}
\newcounter{faketocdepth}
\newif\iffirstitem
\newif\iflastitem
\NewDocumentCommand{\fakeitem}{}{%
\iffirstitem
\firstitemfalse
\else
\iflastitem
\global\lastitemfalse
\else
\unskip\dotfill\mbox{}\par
\fi
\fi
\olditem
}
\NewDocumentEnvironment{faketoc}{O{}}{%
\stepcounter{faketocdepth}% Step faketoc depth
\ifnum\value{faketocdepth}=1
\let\olditem\item
\else
\unskip\dotfill\mbox{}\par% Insert \dotfill for every item that's not the first
\fi
\begin{faketocaux}[#1]
\firstitemtrue
\let\item\fakeitem
}{%
\unskip\dotfill\mbox{}\par% Insert \dotfill at \end{faketoc}
\global\lastitemtrue
\end{faketocaux}
\addtocounter{faketocdepth}{-1}% Unstep faketoc depth
}
\begin{document}
\begin{faketoc}
\item One
\begin{faketoc}
\item Two
\item Three
\begin{faketoc}
\item Two
\item Three
\item Four
\end{faketoc}
\item Four
\end{faketoc}
\item Five
\item Six
\end{faketoc}
\end{document}