我想制作一个包含一系列问题和答案的页面。我想列举带有前缀 Q 的问题和带有前缀 A 的答案。此外,我还想创建可以通过组号识别的问答组。让我举个例子:
Q1 How many countries are there in the world?
A1 There are 196 countries in the world today. Unless you don't count Taiwan…
Q1.1 How many countries are there in Europe?
A1.1 Approximately 50 countries.
Q1.2 How many countries are there in Asia?
A1.2 48.
Q2 What is the population of the world?
A2 Around 7.4 billion people
Q2.1 What is the population of the US?
A2.1 324,532,828 as of Sunday, September 4, 2016.
Q2.1.1 What is the population of Nevada state?
A2.1.1 Around 2,943,409.
编辑:我尝试了这个代码:
\documentclass{article}
\usepackage{enumerate}
\usepackage[shortlabels]{enumitem}
\begin{document}
\begin{enumerate}[start=1,label={(\bfseries Q\arabic*):}]
\item How many countries are there in the world?
There are 196 countries in the world today. Unless you don't count Taiwan…
\begin{enumerate}
\item How many countries are there in Europe?
Approximately 50 countries.
\item How many countries are there in Asia?
48.
\end{enumerate}
\item What is the population of the world?
Around 7.4 billion people
\begin{enumerate}
\item What is the population of the US?
324,532,828 as of Sunday, September 4, 2016.
\begin{enumerate}
\item What is the population of Nevada state?
\end{enumerate}
Around 2,943,409.
\end{enumerate}
\end{enumerate}
\end{document}
答案1
鉴于有可用于排版示例、问题和答案等的软件包,不清楚自己做这件事是否有意义。不过,如果你想自己动手,我会尝试以下方法。
我放弃了enumerate
。用 加载它是没有意义的enumitem
,特别是如果你要求后者用 来模拟前者shortlabels
。
根据您的问题我假设您想要:
- 左边距无缩进;
- 无论级别如何,列表中的项目之间没有额外的垂直间距。
由于这并非完全简单,如果您不是故意的,您应该更清楚您的愿望。
我尽力从您的问题和代码中了解您的需求,我使用了一个questions
用 定义的3 级列表enumitem
。在列表中\qn
创建一个问题并\ans
创建一个答案。
因此,
\begin{questions}
\qn How many countries are there in the world?
\ans There are 196 countries in the world today. Unless you don't count Taiwan…
\begin{questions}
\qn How many countries are there in Europe?
\ans Approximately 50 countries.
\qn How many countries are there in Asia?
\ans 48.
\end{questions}
\qn What is the population of the world?
\ans Around 7.4 billion people
\begin{questions}
\qn What is the population of the US?
\ans 324,532,828 as of Sunday, September 4, 2016.
\begin{questions}
\qn What is the population of Nevada state?
\ans Around 2,943,409.
\end{questions}
\end{questions}
\end{questions}
生产
代码:
\documentclass{article}
\usepackage{enumitem}
\makeatletter
\newlist{questions}{enumerate}{3}
\setlist[questions]{itemindent=0pt, labelwidth=!,align=parleft,itemsep=\lineskip,parsep=\lineskip}
\setlist[questions,1]{label=Q\,\arabic*,leftmargin=1.5\parindent,labelindent=0pt,ref=\arabic*}
\setlist[questions,2]{label=Q\,\arabic{questionsi}.\arabic*,leftmargin=.5\parindent,labelindent=-1.5\parindent,ref=\arabic{questionsi}.\arabic*,topsep=\lineskip,partopsep=\lineskip}
\setlist[questions,3]{label=Q\,\arabic{questionsi}.\arabic{questionsii}.\arabic*,leftmargin=.5\parindent,labelindent=-2\parindent,ref=\arabic{questionsi}.\arabic{questionsii}.\arabic*,topsep=\lineskip,partopsep=\lineskip}
\newcommand*\qn{\stepcounter{cntquestions}\item\label{qn:\thecntquestions}}
\newcommand*\ans{\item[A\,\ref{qn:\thecntquestions}]}
\newcounter{cntquestions}
\setcounter{cntquestions}{0}
\makeatother
\begin{document}
\begin{questions}
\qn How many countries are there in the world?
\ans There are 196 countries in the world today. Unless you don't count Taiwan…
\begin{questions}
\qn How many countries are there in Europe?
\ans Approximately 50 countries.
\qn How many countries are there in Asia?
\ans 48.
\end{questions}
\qn What is the population of the world?
\ans Around 7.4 billion people
\begin{questions}
\qn What is the population of the US?
\ans 324,532,828 as of Sunday, September 4, 2016.
\begin{questions}
\qn What is the population of Nevada state?
\ans Around 2,943,409.
\end{questions}
\end{questions}
\end{questions}
\end{document}
答案2
我确信其中一个包提到克里斯蒂安·胡普弗会做得更好,但这里有一个针对您的特定问题的快速解决方案。
正如所提到的成本加运费,不应该加载两个解决相同问题的包,如enumerate
和enumitem
。enumerate
因此已被禁用。
输出
代码
\documentclass{article}
\usepackage[shortlabels]{enumitem}
\newcommand{\Answer}[1]{%
\item[\bfseries(A\arabic{enumi}):] #1
}
\newcommand{\SubAnswer}[1]{%
\item[(a\arabic{enumii}):] #1
}
\begin{document}
\begin{enumerate}[start=1,label={\bfseries(Q\arabic*):}]
\item How many countries are there in the world?
\Answer{Depends on who is doing the counting}
\begin{enumerate}
\item How many countries are there in Europe?
Approximately 50 countries.
\item How many countries are there in Asia?
48.
\end{enumerate}
\item What is the population of the world?
\Answer{Around 7.4 billion people}
\begin{enumerate}
\item What is the population of the US?
324,532,828 as of Sunday, September 4, 2016.
\begin{enumerate}
\item What is the population of Nevada state?
\end{enumerate}
\SubAnswer{Around 2,943,409.}
\end{enumerate}
\end{enumerate}
\end{document}
[![enter image description here][1]][1]