我是 TeX StackExchange 的新手。我一直在使用我在这里找到的排序列表函数(按字母顺序显示 itemize 中的项目),我遇到了一个问题,我花了几个小时在网上寻找但找不到。我也无法对这个人的帖子发表评论(声誉点数不足),我意识到这个问题完全有可能脱离这个背景。
我的项目sortedlist
很长:
\documentclass{article}
\usepackage{datatool}
\newcommand{\sortitem}[1]{%
\DTLnewrow{list}% Create a new entry
\DTLnewdbentry{list}{description}{#1}% Add entry as description
}
\newenvironment{sortedlist}{%
\DTLifdbexists{list}{\DTLcleardb{list}}{\DTLnewdb{list}}% Create
}{%
\DTLsort{description}{list}% Sort list
\begin{itemize}%
\DTLforeach*{list}{\theDesc=description}{%
\item \text{\theDesc}}% Print each item
\end{itemize}%
}
\begin{document}
\section{section1}
\subsection{Further Reading}
All lists of readings and references are in alphabetical order.
\begin{sortedlist}
\sortitem{Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt \\ ut labore et dolore magna aliqua. Ut enim ad minim veniam Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam}
\sortitem{quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat \\ quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat}
\sortitem{Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu \\ fugiat nulla pariatur Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur}
\end{sortedlist}
\end{document}
我故意在较早的位置切断了该行,以测试该行是否会首先切断。即使有换行符,文本仍会继续显示在页面上。它看起来像这样:
sortedlist
我可以在或定义中放入任何代码sorteditem
来确保这种情况不会发生吗?还是我的换行符不正确?
提前致谢!
答案1
您链接到的答案使用以下方法打印排序列表中的每个元素
\item \theDesc
而你的代码使用
\item \text{\theDesc}
从amsmath
(加载者datatool
)用原始定义替换它:
\documentclass{article}
\usepackage{datatool}
\newcommand{\sortitem}[1]{%
\DTLnewrow{list}% Create a new entry
\DTLnewdbentry{list}{description}{#1}% Add entry as description
}
\newenvironment{sortedlist}{%
\DTLifdbexists{list}{\DTLcleardb{list}}{\DTLnewdb{list}}% Create
}{%
\DTLsort{description}{list}% Sort list
\begin{itemize}%
\DTLforeach*{list}{\theDesc=description}{%
\item \theDesc}% Print each item
\end{itemize}%
}
\begin{document}
\section{section1}
\subsection{Further Reading}
All lists of readings and references are in alphabetical order.
\begin{sortedlist}
\sortitem{Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt \\
ut labore et dolore magna aliqua. Ut enim ad minim veniam Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam}
\sortitem{quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat \\
quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat}
\sortitem{Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu \\
fugiat nulla pariatur Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur}
\end{sortedlist}
\end{document}