我想要写如下代码:
...
\item
\textbf{Differentiation}.
Differentiate with respect to $x$:
\begin{exercises}{3}
\item$x^{2} - 3x$.
\item$x^{5} - \dfrac{x^3}{3}$.
\item$x + \dfrac{1}{x}$.
...
\end{exercises}
\item
Differentiate with respect to $x$:
\begin{exercises}{2}
\item$y = x\cos\frac{1}{2}x$.
\item$y = \sin\left(\dfrac{\pi x}{180}\right)$.
\item$y = \frac{x^2}{1+x}$.
...
\end{exercises}
...
...
但如果我使用shortlst
包作为建议一个用来安排练习的环境,与常见的枚举列表非常相似\item Differentiate with respect to $x$
,上图第二行以后的内容会排版成三列。
----编辑---- 使用环境的建议minipage
受到预先定义的小页面宽度的限制,也就是说,它不适合不同的页面宽度。改变
\documentclass{article}
\usepackage{shortlst}
\usepackage[width=10cm]{geometry}
\usepackage{lipsum}
\begin{document}
\lipsum[1]
\newenvironment{exercises}[1]
{#1:\\ \begin{minipage}[t]{0.9\textwidth}\begin{shortenumerate}}
{\end{shortenumerate}\end{minipage}}
\begin{enumerate}
\item
\begin{exercises}{\textbf{Differentiation}\\ Differentiate with respect to $x$}
\item $x^3-3x$
\item $x^5-\frac{x^3}{3}$
\item $x+\frac{1}{x}$
\item $(x+1)^2(x-1)^2$
\item $x\sin x$
\end{exercises}
\item
\begin{exercises}{Differentiate with respect to $x$}
\item $y=x\cos \frac{1}{2}x$
\item $y=\sin\left(\frac{\pi x}{180}\right)$
\item $y=\frac{x^2}{1+x}$
\end{exercises}
\end{enumerate}
\end{document}
到
\documentclass{article}
\usepackage{shortlst}
\usepackage[width=9cm]{geometry}
\usepackage{lipsum}
\begin{document}
\lipsum[1]
\newenvironment{exercises}[1]
{#1:\\ \begin{minipage}[t]{0.9\textwidth}\begin{shortenumerate}}
{\end{shortenumerate}\end{minipage}}
\begin{enumerate}
\item
\begin{exercises}{\textbf{Differentiation}\\ Differentiate with respect to $x$}
\item $x^3-3x$
\item $x^5-\frac{x^3}{3}$
\item $x+\frac{1}{x}$
\item $(x+1)^2(x-1)^2$
\item $x\sin x$
\end{exercises}
\item
\begin{exercises}{Differentiate with respect to $x$}
\item $y=x\cos \frac{1}{2}x$
\item $y=\sin\left(\frac{\pi x}{180}\right)$
\item $y=\frac{x^2}{1+x}$
\end{exercises}
\end{enumerate}
\end{document}
将会得到
Schweinebacke 给出的代码也是如此,除非我单独更改宽度
\documentclass{article}
\usepackage{shortlst}% http://ctan.org/pkg/shortlst
\usepackage{scrextend}
\usepackage{lipsum}
\usepackage[width=10cm]{geometry} %added
\begin{document}
\lipsum[1]
\begin{enumerate}
\item {Differentiate with respect to $x$:
\begin{addmargin}[0pt]{0.1\linewidth}
\begin{shortenumerate}
\item $x^3-3x$
\item $x^5-\frac{x^3}{3}$
\item $x+\frac{1}{x}$
\item $(x+1)^2(x-1)^2$
\item $x\sin x$
\end{shortenumerate}
\end{addmargin}
}
\item {Differentiate with respect to $x$:
\begin{addmargin}[0pt]{.4\linewidth}
\begin{shortenumerate}
\item $y=x\cos \frac{1}{2}x$
\item $y=\sin\left(\frac{\pi x}{180}\right)$
\item $y=\frac{x^2}{1+x}$
\item $y=x\cos \frac{1}{2}x$
\item $y=\sin\left(\frac{\pi x}{180}\right)$
\item $y=\frac{x^2}{1+x}$
\item $y=x\cos \frac{1}{2}x$
\item $y=\sin\left(\frac{\pi x}{180}\right)$
\item $y=\frac{x^2}{1+x}$
\item $y=x\cos \frac{1}{2}x$
\item $y=\sin\left(\frac{\pi x}{180}\right)$
\item $y=\frac{x^2}{1+x}$
\end{shortenumerate}
\end{addmargin}
}
\end{enumerate}
\end{document}
答案1
的结果你之前的问题,可能在一个小页面中,普通的枚举环境应该会得到您想要的结果。
\documentclass{article}
\usepackage{shortlst}% http://ctan.org/pkg/shortlst
\begin{document}
\newenvironment{exercises}[1]
{#1:\\ \begin{minipage}[t]{0.9\textwidth}\begin{shortenumerate}}
{\end{shortenumerate}\end{minipage}}
\begin{enumerate}
\item
\begin{exercises}{\textbf{Differentiation}\\ Differentiate with respect to $x$}
\item $x^3-3x$
\item $x^5-\frac{x^3}{3}$
\item $x+\frac{1}{x}$
\item $(x+1)^2(x-1)^2$
\item $x\sin x$
\end{exercises}
\item
\begin{exercises}{Differentiate with respect to $x$}
\item $x^3-3x$
\item $x^5-\frac{x^3}{3}$
\item $x+\frac{1}{x}$
\item $(x+1)^2(x-1)^2$
\item $x\sin x$
\end{exercises}
\end{enumerate}
\end{document}
看起来像
如果您想要一个像表一样的环境来处理特定数量的方程式列,那么您可以定义一个新的计数器来执行此操作。
\newcounter{innerlist}
\renewcommand{\theinnerlist}{\arabic{innerlist}}
\newcommand{\inneritem}[1]{\refstepcounter{innerlist}\theinnerlist.\ #1}
\newenvironment{exercises}[2]
{\setcounter{innerlist}{0}\begin{minipage}[t]{0.9\textwidth}#1:\\ \begin{tabular}{#2}}
{\end{tabular}\end{minipage}}
\begin{enumerate}
\item
\begin{exercises}{\textbf{Differentiation}\\ Differentiate with respect to $x$}{ll}
\inneritem{$x^3-3x$} & \inneritem{$x^5-\frac{x^3}{3}$}\\
\inneritem{$x+\frac{1}{x}$} & \inneritem{$(x+1)^2(x-1)^2$}\\
\inneritem{$x\sin x$} & \inneritem{$x\sin x$}
\end{exercises}
\item
\begin{exercises}{\textbf{Differentiation}\\ Differentiate with respect to $x$}{lll}
\inneritem{$x^3-3x$} & \inneritem{$x^5-\frac{x^3}{3}$} & \inneritem{$x+\frac{1}{x}$}\\
\inneritem{$(x+1)^2(x-1)^2$} & \inneritem{$x\sin x$} & \inneritem{$x\sin x$}
\end{exercises}
\end{enumerate}
此版本不应该存在跨页面扩展的重大问题。每个小页面都不应该跨页面扩展,但外部枚举列表中的项目可以正常扩展。
使用 longtables 包的修改允许它跨页面运行:
\newenvironment{exercises}[2]
{\setcounter{innerlist}{0}#1:\\ \begin{longtable}[t]{#2}}
{\end{longtable}}
答案2
multicols
您可以将与newlist
使用包的组合使用enumitem
,如下所示。
它也允许分页。
\documentclass{article}
\usepackage{lipsum}
\usepackage{multicol} % multicols
\usepackage{enumitem} % customized lists
\usepackage[width=10cm]{geometry} % page dimensions
% setup a new list (terminology from enumitem)
\newlist{mylist}{enumerate}{5}
\setlist[mylist]{label=(\alph*)}
\newenvironment{exercises}[1]{\begin{multicols}{#1}\begin{mylist}}{\end{mylist}\end{multicols}}
\begin{document}
\vspace*{4cm} % purely to demonstrate the pagebreak
\lipsum[1-2]
\begin{enumerate}
\item {Differentiate with respect to $x$:}
\begin{exercises}{2}
\item $x^3-3x$
\item $x^5-\frac{x^3}{3}$
\item $x+\frac{1}{x}$
\item $(x+1)^2(x-1)^2$
\item $x\sin x$
\end{exercises}
\item Differentiate with respect to $x$:
\begin{exercises}{2}
\item $y=x\cos \frac{1}{2}x$
\item $y=\sin\left(\frac{\pi x}{180}\right)$
\item $y=\frac{x^2}{1+x}$
\item $y=x\cos \frac{1}{2}x$
\item $y=\sin\left(\frac{\pi x}{180}\right)$
\item $y=\frac{x^2}{1+x}$
\item $y=x\cos \frac{1}{2}x$
\item $y=\sin\left(\frac{\pi x}{180}\right)$
\item $y=\frac{x^2}{1+x}$
\item $y=x\cos \frac{1}{2}x$
\item $y=\sin\left(\frac{\pi x}{180}\right)$
\item $y=\frac{x^2}{1+x}$
\end{exercises}
\end{enumerate}
\end{document}
答案3
我建议将马克的答案与包结合起来屏幕扩展。这将支持练习中的分页符:
\documentclass{article}
\usepackage{shortlst}% http://ctan.org/pkg/shortlst
\usepackage{scrextend}
\usepackage{lipsum}
\begin{document}
\lipsum[1-4]
\begin{enumerate}
\item {Differentiate with respect to $x$:
\begin{addmargin}[0pt]{2em}
\begin{shortenumerate}
\item $x^3-3x$
\item $x^5-\frac{x^3}{3}$
\item $x+\frac{1}{x}$
\item $(x+1)^2(x-1)^2$
\item $x\sin x$
\end{shortenumerate}
\end{addmargin}
}
\item {Differentiate with respect to $x$:
\begin{addmargin}[0pt]{2em}
\begin{shortenumerate}
\item $y=x\cos \frac{1}{2}x$
\item $y=\sin\left(\frac{\pi x}{180}\right)$
\item $y=\frac{x^2}{1+x}$
\item $y=x\cos \frac{1}{2}x$
\item $y=\sin\left(\frac{\pi x}{180}\right)$
\item $y=\frac{x^2}{1+x}$
\item $y=x\cos \frac{1}{2}x$
\item $y=\sin\left(\frac{\pi x}{180}\right)$
\item $y=\frac{x^2}{1+x}$
\item $y=x\cos \frac{1}{2}x$
\item $y=\sin\left(\frac{\pi x}{180}\right)$
\item $y=\frac{x^2}{1+x}$
\end{shortenumerate}
\end{addmargin}
}
\end{enumerate}
\end{document}
注意:如果您已经使用KOMA-Script 类您不需要加载该包scrextend
。
您可以为此定义一个环境:
\documentclass{article}
\usepackage{shortlst}% http://ctan.org/pkg/shortlst
\usepackage{scrextend}
\usepackage{lipsum}%
\usepackage[width=10cm]{geometry} %added
\newenvironment{exercise}[1][\strut]{%
\item #1\begin{addmargin}[0pt]{2em}\begin{shortenumerate}
}{%
\end{shortenumerate}\end{addmargin}
}
\begin{document}
\lipsum[1]
\begin{enumerate}
\begin{exercise}[{Differentiate with respect to $x$:}]
\item $x^3-3x$
\item $x^5-\frac{x^3}{3}$
\item $x+\frac{1}{x}$
\item $(x+1)^2(x-1)^2$
\item $x\sin x$
\end{exercise}
\begin{exercise}[{Differentiate with respect to $x$:}]
\item $y=x\cos \frac{1}{2}x$
\item $y=\sin\left(\frac{\pi x}{180}\right)$
\item $y=\frac{x^2}{1+x}$
\item $y=x\cos \frac{1}{2}x$
\item $y=\sin\left(\frac{\pi x}{180}\right)$
\item $y=\frac{x^2}{1+x}$
\item $y=x\cos \frac{1}{2}x$
\item $y=\sin\left(\frac{\pi x}{180}\right)$
\item $y=\frac{x^2}{1+x}$
\item $y=x\cos \frac{1}{2}x$
\item $y=\sin\left(\frac{\pi x}{180}\right)$
\item $y=\frac{x^2}{1+x}$
\end{exercise}
\end{enumerate}
\end{document}
答案4
这是使用{tasks}
提供的环境的另一种解决方案exsheets
包。但它至少有一个缺点:它不能安全地与其他{tasks}
环境嵌套。(虽然语法相似,但它不是 LaTeX 意义上的真正列表。)
环境有一个可选参数,用于指定列数:
\begin{tasks}{<num of cols>}
\task first item
\task second item
...
\end{tasks}
以下是完整示例:
\documentclass{article}
\usepackage[load-headings]{exsheets}
\SetupExSheets{
% first the number then the title:
headings=block-rev,
% number tasks (a), (b), ...
tasks/label=(tsk[a]),
% make sure the task item labels have enough space:
tasks/label-width=2em
}
\usepackage{lipsum}% dummy text
\begin{document}
\lipsum[1]\bigskip
\begin{question}[name=Differentiation]
Differentiate with respect to $x$:
\begin{tasks}{3}% three columns
\task $x^3-3x$
\task $x^5-\frac{x^3}{3}$
\task $x+\frac{1}{x}$
\task $(x+1)^2(x-1)^2$
\task $x\sin x$
\end{tasks}
\end{question}
\begin{question}[name=More Differentiation]
Differentiate with respect to $x$:
\begin{tasks}{2}% two columns
\task $y=x\cos \frac{1}{2}x$
\task $y=\sin\left(\frac{\pi x}{180}\right)$
\task $y=\frac{x^2}{1+x}$
\task $y=x\cos \frac{1}{2}x$
\task $y=\sin\left(\frac{\pi x}{180}\right)$
\task $y=\frac{x^2}{1+x}$
\task $y=x\cos \frac{1}{2}x$
\task $y=\sin\left(\frac{\pi x}{180}\right)$
\task $y=\frac{x^2}{1+x}$
\task $y=x\cos \frac{1}{2}x$
\task $y=\sin\left(\frac{\pi x}{180}\right)$
\task $y=\frac{x^2}{1+x}$
\end{tasks}
\end{question}
\end{document}