我怎样才能在枚举环境中对齐项目?

我怎样才能在枚举环境中对齐项目?

我使用枚举环境,并且希望某些项目与水平编号位于同一行。我不想使用multicoltasks包,因此我找到了以下代码:

\makeatletter
\newcommand{\initem}{\ifnum\enit@type=\z@\refstepcounter{\@listctr}\fi
                     \hspace{20pt}\@itemlabel\hspace{\labelsep}}
\makeatother

但是由于命令的原因,项目每次的宽度都不同,而项目之间的水平间距是特定的\hspace。我如何才能每次都获得正确的间距,以便项目垂直对齐?

\documentclass{article}

\usepackage[textheight=21cm,textwidth=16cm,]{geometry}
\usepackage{enumitem}

\setlength{\parindent}{0pt}
\everymath{\displaystyle}

\makeatletter
\newcommand{\initem}{\ifnum\enit@type=\z@\refstepcounter{\@listctr}\fi
                     \hspace{20pt}\@itemlabel\hspace{\labelsep}}
\makeatother

\begin{document}

Example 1 -- Two columns \\
\rule{0.5\linewidth}{0.5pt} \\
\hphantom{\rule{0.5\linewidth}{0.5pt}}
\rule{0.5\linewidth}{0.5pt}
\begin{enumerate}
    \item   $f(x)=2x^3-3x^2+5x-1$
    \initem $f(x)= \frac{x+3}{2x-4}$
    \item   $f(x)= \sqrt{3x-12}$
    \initem $f(x)= \frac{2}{\sqrt{6-2x}}$
\end{enumerate}

\vspace{1cm}

Example 2 -- Three columns \\
\rule{0.333\linewidth}{0.5pt} \\
\hphantom{\rule{0.333\linewidth}{0.5pt}}
\rule{0.333\linewidth}{0.5pt} \\
\hphantom{\rule{0.333\linewidth}{0.5pt}}
\hphantom{\rule{0.333\linewidth}{0.5pt}}
\rule{0.334\linewidth}{0.5pt}
\begin{enumerate}
    \item   $f(x)=2x^3-3x^2+1$
    \initem $f(x)= \frac{x+3}{2x-4}$
    \initem $f(x)= \sqrt{3x-12}$
    \item   $f(x)= \frac{2}{\sqrt{x^2-1}}$
    \initem $f(x)= \frac{x}{x+1}$
    \initem $f(x)= \sqrt{x+\frac{1}{x}}$
\end{enumerate}

\end{document}

在此处输入图片描述

答案1

multicol软件包就是为此而设计的。您应该使用它。

以下是如何将其应用到您的示例中:

\documentclass{article}

\usepackage[textheight=21cm,textwidth=16cm,]{geometry}
\usepackage{enumitem}
\usepackage{multicol}

\setlength{\parindent}{0pt}
\everymath{\displaystyle}

\makeatletter
\newcommand{\initem}{\ifnum\enit@type=\z@\refstepcounter{\@listctr}\fi
                     \hspace{20pt}\@itemlabel\hspace{\labelsep}}
\makeatother

\begin{document}

Example 1 -- Two columns \\
\rule{0.5\linewidth}{0.5pt} \\
\hphantom{\rule{0.5\linewidth}{0.5pt}}
\rule{0.5\linewidth}{0.5pt}
\begin{multicols}{2}
\begin{enumerate}
    \item   $f(x)=2x^3-3x^2+5x-1$
    \item $f(x)= \frac{x+3}{2x-4}$
    \item   $f(x)= \sqrt{3x-12}$
    \item $f(x)= \frac{2}{\sqrt{6-2x}}$
\end{enumerate}
\end{multicols}

\vspace{1cm}


Example 2 -- Three columns \\
\rule{0.333\linewidth}{0.5pt} \\
\hphantom{\rule{0.333\linewidth}{0.5pt}}
\rule{0.333\linewidth}{0.5pt} \\
\hphantom{\rule{0.333\linewidth}{0.5pt}}
\hphantom{\rule{0.333\linewidth}{0.5pt}}
\rule{0.334\linewidth}{0.5pt}
\begin{multicols}{3}
\begin{enumerate}
    \item   $f(x)=2x^3-3x^2+1$
    \item $f(x)= \frac{x+3}{2x-4}$
    \item $f(x)= \sqrt{3x-12}$
    \item   $f(x)= \frac{2}{\sqrt{x^2-1}}$
    \item $f(x)= \frac{x}{x+1}$
    \item $f(x)= \sqrt{x+\frac{1}{x}}$
\end{enumerate}
\end{multicols}

\end{document}

在此处输入图片描述


原始示例threeparttable下面是一个与's 结合使用的示例tablenotes,用于演示其在列表中的用法。它摘自我的论文,用于说明输出;最有趣的部分是 和 之间\begin{multicols}[2]。它也 \end{multicols}可以与更传统的 s 很好地配合使用:\itemmulticols 示例输出

\begin{threeparttable}
\caption[High\hyp{}frequency\hyp{}related material parameters.]{\label{tab_Theory_Materials}High\hyp{}frequency\hyp{}related material parameters.  Based on a table in reference \citenumns{Mishra_RF_Amps}, some data from reference \citenumns{Willardson_SiC}.}
\small{
\begin{tabular}{@{}l@{}S@{}S@{}S@{}S@{}S@{}S@{}S@{}S@{}}
    \toprule
    &\multicolumn{1}{c}{$E_g$\tnote{a}}&\multicolumn{1}{c}{$n_i$\tnote{b}}&\multicolumn{1}{c}{$\epsilon_r$\tnote{c}}&\multicolumn{1}{c}{$\mu_n$\tnote{d}}& \multicolumn{1}{c}{$v_\mathrm{sat}$\tnote{e}}&\multicolumn{1}{c}{$E_\mathrm{br}$\tnote{f}}&\multicolumn{1}{c}{$\mathit{TC}$\tnote{g}}& \multicolumn{1}{c}{$\mathit{JM}$\tnote{h}}\\
    &\multicolumn{1}{c}{\small{\si{\eV}}}&\multicolumn{1}{c}{\small{\si{\cm^{-3}}}}&\multicolumn{1}{c}{}&\multicolumn{1}{c}{\small{\si{\cm\per\volt\per\s}}}& \multicolumn{1}{c}{\small{$\times 10^7$\si{\cm\per\s}}}&\multicolumn{1}{c}{\small{\si{\mega\volt\per\cm}}}&\multicolumn{1}{c}{\small{\Wmk}}&\multicolumn{1}{c}{}\\
    \midrule\\
    Si&1.1&1.5e10&11.8&1350&1.0&0.3&150&1\\
    %\sisetup{scientific-notation=true}
    GaAs&1.42&1.5e5&13.1&8500&1.0&0.6&43&2.7\\
    %\sisetup{scientific-notation=false}
    SiC (4H)&3.26&8.2e-9&10&700&2.0&3.0&450\tnote{~i}&20\\
    GaN&3.4&1.9e-10&9.0&2000\tnote{~j}&2.5&3.3&130&27.5\\
    Diamond&5.4&1.6e-27&5.5&1900&2.7&5.6&2000&50\\
    \bottomrule 

\end{tabular}}
\begin{tablenotes}
    \setlength{\columnsep}{0.8cm}
    \setlength{\multicolsep}{0cm}
    \begin{multicols}{2}\raggedright
        \item[a] Bandgap.
        \item[b] \rep{Intrinsic c}{C}arrier density \add{at room temperature}.
        \item[c] Relative permittivity.
        \item[d] Electron mobility.
        \item[e] Saturation velocity.
        \item[f] Breakdown field. 
        \item[g] \Acl{TC} \add{at room temperature. The \acl{TC} reduces with temperature at typical operating temperatures,\supercite{Luo_TC_T} for GaN $\mathit{TC}\propto T^{-1.4}$ is often used, though values vary}.
        \item[h] Johnson figure of merit, which compares the power\hyp{}frequency performance of materials, normalised to the value for Si. $JM=\rfrac{E_\mathrm{br}v_\mathrm{sat}}{2\pi}$.
        \item[i] In-plane; parallel to the $c$-axis the \acl{TC} is 330~\Wmk.
        \item[j] Within the \acs{2DEG}; the bulk value is \SI[scientific-notation=false]{1200}{\cm\per\volt\per\s}.
    \end{multicols}
\end{tablenotes}
\end{threeparttable}

答案2

你说你不喜欢tasks这个包,但到现在也没说为什么不喜欢它(我在评论中问了这个问题)。此外,你展示的水平线的用途也不清楚。

但是,对于您在问题中展示的情况,该tasks软件包已经开发出来了。有了它,您可以简单地水平和垂直对齐项目:

在此处输入图片描述


\documentclass{article}
\usepackage[textheight=21cm,textwidth=16cm]{geometry}
\usepackage{amsmath}
\usepackage{tasks}
\settasks{
    label = \arabic*.
        }

\begin{document}

Example 1 -- Two columns 
    \begin{tasks}(2)
\task   $f(x) = 2x^3-3x^2+5x-1$
\task   $f(x) = \dfrac{x+3}{2x-4}$
\task   $f(x) = \sqrt{3x-12}$
\task   $f(x) = \dfrac{2}{\sqrt{6-2x}}$
    \end{tasks}

\vspace{1cm}

Example 2 -- Three columns 
    \begin{tasks}(3)
\task   $f(x) = 2x^3-3x^2+1$
\task   $f(x) = \dfrac{x+3}{2x-4}$
\task   $f(x) = \sqrt{3x-12}$
\task   $f(x) = \dfrac{2}{\sqrt{x^2-1}}$
\task   $f(x) = \dfrac{x}{x+1}$
\task   $f(x) = \sqrt{x+\dfrac{1}{x}}$
    \end{tasks}

\end{document}

使用eninumitem包实现类似的结果非常困难,甚至不可能。但是,不使用tasks包的情况下,您可以使用以下方法获得类似的结果array


\documentclass{article}
\usepackage[fleqn]{nccmath}
\usepackage{booktabs}

\begin{document}

Example 1 -- Two columns 

$\displaystyle
    \begin{array}{cc @{\qquad} cc}
1.  &  f(x) = 2x^3-3x^2+5x-1    & 2.&  f(x) = \dfrac{x+3}{2x-4}    \\
    \addlinespace
3.  &  f(x) = \sqrt{3x-12}      & 4.&  f(x) = \dfrac{2}{\sqrt{6-2x}}
    \end{array}
$
\end{document}

在此处输入图片描述

答案3

我的解决方案

\documentclass[a4paper,12pt]{article}

\usepackage[margin=1in]{geometry}
\usepackage{enumitem}
\usepackage{etoolbox}

\everymath{\displaystyle}
\setlength{\parindent}{0pt}

\renewcommand{\labelenumi}{\large\textbf{\arabic{enumi}{.}}}
\renewcommand{\labelenumii}{\alph{enumii}{)}}

%--------------------------------------------------------------------------
\newlength{\enumlen}
\AtBeginEnvironment{enumerate}{\setlength{\enumlen}{\linewidth}}
\makeatletter
\newcommand{\initem}[2][]{
    \ifx&#1&
        \ifnum\enit@type=\z@\refstepcounter{\@listctr}\fi
        \hfill
        \makebox[0.5\enumlen][l]
        {\makebox[\labelwidth][r]{\@itemlabel}\hspace{\labelsep}{#2}}
    \else
        \ifnum\enit@type=\z@\refstepcounter{\@listctr}\fi
        \hfill
        \makebox[\dimexpr(\enumlen/3)][l]
        {\makebox[\labelwidth][r]{\@itemlabel}\hspace{\labelsep}{#1}}%
        \ifnum\enit@type=\z@\refstepcounter{\@listctr}\fi
        \makebox[\dimexpr(\enumlen/3)][l]
        {\makebox[\labelwidth][r]{\@itemlabel}\hspace{\labelsep}{#2}}
    \fi
}
\makeatother
%--------------------------------------------------------------------------
\begin{document}
\begin{enumerate}
    \item
\rule{0.5\linewidth}{0.5pt}\\
\hphantom{\rule{0.5\linewidth}{0.5pt}}\rule{0.5\linewidth}{0.5pt}
    \begin{enumerate}
        \item   $f(x)=2x^3-3x^2$
        \initem {$f(x)=2x^3-3x^2$}
        \item   $f(x)=2x^3-3x^2$
        \initem {$f(x)=2x^3-3x^2$}
        \item   $f(x)=2x^3-3x^2$
        \initem {$f(x)=2x^3-3x^2$}
    \end{enumerate}
    \item
\rule{0.33333\linewidth}{0.5pt}\\
\hphantom{\rule{0.33333\linewidth}{0.5pt}}\rule{0.33333\linewidth}{0.5pt}\\
\hphantom{\rule{0.66666\linewidth}{0.5pt}}\rule{0.33333\linewidth}{0.5pt}
    \begin{enumerate}
        \item   $f(x)=2x^3-3x^2$
        \initem [$f(x)=2x^3-3x^2$]
                {$f(x)=2x^3-3x^2$}
        \item   $f(x)=2x^3-3x^2$
        \initem [$f(x)=2x^3-3x^2$]
                {$f(x)=2x^3-3x^2$}
        \item   $f(x)=2x^3-3x^2$
        \initem [$f(x)=2x^3-3x^2$]
                {$f(x)=2x^3-3x^2$}
        \item   $f(x)=2x^3-3x^2$
        \initem [$f(x)=2x^3-3x^2$]
                {$f(x)=2x^3-3x^2$}
        \item
\rule{0.5\linewidth}{0.5pt}\\
\hphantom{\rule{0.5\linewidth}{0.5pt}}\rule{0.5\linewidth}{0.5pt}
        \begin{enumerate}
            \item   $f(x)=2x^3-3x^2$
            \initem {$f(x)=2x^3-3x^2$}
            \item   $f(x)=2x^3-3x^2$
            \initem {$f(x)=2x^3-3x^2$}
            \item   $f(x)=2x^3-3x^2$
            \initem {$f(x)=2x^3-3x^2$}
            \item   $f(x)=2x^3-3x^2$
            \initem {$f(x)=2x^3-3x^2$}
            \item   $f(x)=2x^3-3x^2$
            \initem {$f(x)=2x^3-3x^2$}
        \end{enumerate}
        \item
\rule{0.33333\linewidth}{0.5pt}\\
\hphantom{\rule{0.33333\linewidth}{0.5pt}}\rule{0.33333\linewidth}{0.5pt}\\
\hphantom{\rule{0.66666\linewidth}{0.5pt}}\rule{0.33333\linewidth}{0.5pt}
        \begin{enumerate}
            \item   $f(x)=2x^3-3x^2$
            \initem [$f(x)=2x^3-3x^2$]
                    {$f(x)=2x^3-3x^2$}
            \item   $f(x)=2x^3-3x^2$
            \initem [$f(x)=2x^3-3x^2$]
                    {$f(x)=2x^3-3x^2$}
            \item   $f(x)=2x^3-3x^2$
            \initem [$f(x)=2x^3-3x^2$]
                    {$f(x)=2x^3-3x^2$}
        \end{enumerate}
    \end{enumerate}
\end{enumerate}
\end{document}

在此处输入图片描述

答案4

使用包来实现这一点的方法tabularx。这是我几年前在互联网上找到的一段代码(遗憾的是我不记得在哪里找到的了)。在我切换到包之前,我经常使用它tasks

\documentclass{article}

\usepackage[textheight=21cm,textwidth=16cm,]{geometry}
\usepackage{enumitem}

\setlength{\parindent}{0pt}
\everymath{\displaystyle}

\usepackage{tabularx}

\newcounter{row}
\renewcommand{\therow}{\arabic{row}}
\newenvironment{rowenum}[1]
    {\setcounter{row}{0}%
        \par\noindent\tabularx{\linewidth}[t]
        {*{#1}{>{\stepcounter{row}\makebox[1.8em][r]{\therow.\hspace{0.5em}}}X}}%
    }
    {\endtabularx}

\begin{document}

Example 1 -- Two columns \\
\rule{0.5\linewidth}{0.5pt} \\
\hphantom{\rule{0.5\linewidth}{0.5pt}}
\rule{0.5\linewidth}{0.5pt}
\begin{rowenum}{2}
    $f(x)=2x^3-3x^2+5x-1$   &$f(x)= \frac{x+3}{2x-4}$\\
   $f(x)= \sqrt{3x-12}$   &$f(x)= \frac{2}{\sqrt{6-2x}}$
\end{rowenum}

\vspace{1cm}

Example 2 -- Three columns \\
\rule{0.333\linewidth}{0.5pt} \\
\hphantom{\rule{0.333\linewidth}{0.5pt}}
\rule{0.333\linewidth}{0.5pt} \\
\hphantom{\rule{0.333\linewidth}{0.5pt}}
\hphantom{\rule{0.333\linewidth}{0.5pt}}
\rule{0.334\linewidth}{0.5pt}
\begin{rowenum}{3}
   $f(x)=2x^3-3x^2+1$   &$f(x)= \frac{x+3}{2x-4}$   &$f(x)= \sqrt{3x-12}$\\
   $f(x)= \frac{2}{\sqrt{x^2-1}}$   &$f(x)= \frac{x}{x+1}$   &$f(x)= \sqrt{x+\frac{1}{x}}$
\end{rowenum}

\end{document}

tabularx创建一个与文本宽度一样大的表格。该表格被分成我们需要的单元格数量(必需参数)。每个单元格都以一个数字开头,使用 latex 计数器。

这不是完美的解决方案。我一直以为行距太近了。我不得不手动调整行距以使其更易于阅读。这需要大量工作。

相关内容