使用 enumitem 格式化描述列表

使用 enumitem 格式化描述列表

我有几行文本想要对齐成如下所示:

以下是 MWE:

\documentclass{article}
\usepackage{enumitem}
\begin{document}
\begin{description}[labelindent=1em ,labelwidth=1.2cm, labelsep*=1em, leftmargin =!, itemindent= 0pt, style = sameline]
\item[Input:] $a_1,\ldots,a_m$
\item[Output:] Can we do some operation on the given input to get some outcome using this  methodology and using $a_1,\ldots,a_m$?
\end{description}
\end{document}

它为我提供了输出:

作为替代方案,我也尝试过使用\hspace,但eqnarray无济于事。

答案1

您可以使用例如leftmargin =3cm,来获得您想要的东西。

查看完整代码

\documentclass{article}

\usepackage{enumitem}

\begin{document}
\begin{description}[%
  labelindent=1em,
  labelwidth=1.2cm, 
  labelsep*=1em, 
  leftmargin =3cm, % <==================================================
  itemindent= 0pt, 
  style = sameline
]
\item[Input:] $a_1,\ldots,a_m$
\item[Output:] Can we do some operation on the given input to get some outcome using this  methodology and using $a_1,\ldots,a_m$?
\end{description}
\end{document}

结果:

结果

为了获得最小的右移,您可以使用以下代码(使用最长的单词Output:来获取所需的长度):

\begin{description}[%
  widest=Output:, % <===================================================
  itemindent=*,
  leftmargin=* % <======================================================
]
\item[Input:] $a_1,\ldots,a_m$
\item[Output:] Can we do some operation on the given input to get some outcome using this  methodology and using $a_1,\ldots,a_m$?
\end{description}

因此以下完整代码

\documentclass{article}

\usepackage{enumitem}

\begin{document}
\begin{description}[%
  labelindent=1em,
  labelwidth=1.2cm, 
  labelsep*=1em, 
  leftmargin =3cm, % <==================================================
  itemindent= 0pt, 
  style = sameline
]
\item[Input:] $a_1,\ldots,a_m$
\item[Output:] Can we do some operation on the given input to get some outcome using this  methodology and using $a_1,\ldots,a_m$?
\end{description}

\begin{description}[%
  widest=Output:, % <===================================================
  itemindent=*,
  leftmargin=* % <======================================================
]
\item[Input:] $a_1,\ldots,a_m$
\item[Output:] Can we do some operation on the given input to get some outcome using this  methodology and using $a_1,\ldots,a_m$?
\end{description}
\end{document}

显示两种解决方案及其区别:

结果

相关内容