如何以不同的方式组织文档的各个部分

如何以不同的方式组织文档的各个部分

我不完全确定如何表述我的问题,所以我可能也错过了已经存在的答案,而且我对我的标记非常不确定。

所以我有两个不同的想法,我认为可以用同一类型的技术来回答

  • 一种方法是构建一个词汇表文档,例如列“单词”、“类别”(动词、名词、形容词等)、“用法示例”、“含义”。我可以longtable为此做一个不错的选择,但我希望有一种简单的方法来对这个表进行排序,要么按字母顺序,要么按类别。就像一个编译选项,或者只是我可以通过option=1或更改的东西option=2
  • 第二个稍微复杂一些,但想法是一样的:仍然对于语言课,我有一门课程,其中每一章的组织方式总是相同的:

    • 1 词汇
    • 2 概念
    • 3 文本
    • 4 语法

    我希望以一种简单的方式按章节或类别来组织文档,例如每个词汇部分,然后是每个概念等等。

这样的事情可行吗?

答案1

一种可能性是使用datatool。数据可以存储在 CSV 文件中。例如:

Word,Category,Example,Meaning
jump,verb,"The cow jumped over the moon.","To project one's self into the air through the muscular action of feet and legs."
cat,noun,"The cat sat on the mat.","feline animal"
hungry,adjective,"The hungry duck ate some corn.","desire for food"

如果文件名为vocab.csv,则可以使用以下命令加载它:

\DTLloaddb{vocab.csv}{vocab}

然后,您可以使用 根据特定列对其进行排序\DTLsort。例如,按Word列排序:

\DTLsort{Word}{vocab}

然后,您可以使用 迭代数据\DTLforeach。例如:

\documentclass{article}

\usepackage{array}
\usepackage{longtable}
\usepackage{datatool}

\DTLloaddb{vocab}{vocab.csv}

\begin{document}

\section*{Vocabulary List}
\DTLsort{Word}{vocab}% sort the data
\begin{longtable}{ll>{\raggedright}p{.25\linewidth}>{\raggedright}p{.25\linewidth}}
\bfseries Word &
\bfseries Category &
\bfseries Example &
\bfseries Meaning
\DTLforeach*{vocab}% database label
 {\Word=Word,\Category=Category,\Example=Example,\Meaning=Meaning}% placeholder assignments
 {\tabularnewline\Word & \Category & \Example & \Meaning}
\end{longtable}

\section*{Vocabulary List (by Category)}
\DTLsort{Category}{vocab}% sort the data
\begin{longtable}{ll>{\raggedright}p{.25\linewidth}>{\raggedright}p{.25\linewidth}}
\bfseries Word &
\bfseries Category &
\bfseries Example &
\bfseries Meaning
\DTLforeach*{vocab}% database label
 {\Word=Word,\Category=Category,\Example=Example,\Meaning=Meaning}% placeholder assignments
 {\tabularnewline\Word & \Category & \Example & \Meaning}
\end{longtable}

\end{document}

(根据需要更改的参数\begin{longtable}和表头。)

文档图像

由于使用 TeX 进行排序,因此对于大型数据库来说,速度可能非常慢。在这种情况下,您可能需要考虑使用datatooltk执行排序。(在数据排序

您可以将此方法应用于示例的第二部分。(包括概念、文本等的额外列,使用以下方法迭代数据\DTLforeach*并使用在命令=标题列表。)

相关内容