5

I have a few lines of text that I want to be aligned to look like this:

Here is the 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}

which provides me the output:

As alternatives, I have also tried using \hspace, tried eqnarray to no avail.

  • I have been going through enumitem manual and dont you think its possible to set a specific width for the item label so that the item text doesnt come under it? – GermanShepherd Apr 3 at 5:34
6

You can use for example leftmargin =3cm, to get what you want.

See the complete code

\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}

and the result:

result

To get the minimal shift to right you can use the following code (use the longest word Output: to get the needed length):

\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}

So the following complete code

\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}

shows both solutions and there difference:

result

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.