3

Is there any way to align the spilled over line to a particular part within the sentence

I want to align the second line under MS Office....

\textbf{Software} --- MS Office Powerpoint, Software 1, Software 2, Software 3, Software 4, Software 5, Software 6, Software 7, etc. etc.

As of now, I am doing this:

\textbf{Software} --- MS Office Powerpoint, Software 1, Software 2, Software 3, Software 4,\\
\hspace{60pt}Software 5, Software 6, Software 7, etc. etc.
ShreevatsaR
  • 45,428
  • 10
  • 117
  • 149
Karan
  • 137

2 Answers2

3

You could use a tabular environment. Be mindful of overfull boxes, though.

enter image description here

\documentclass{article}
\begin{document}
\noindent
\begin{tabular}{r@{\ }l}
\textbf{Software} ---   & MS Office Powerpoint, Software 1, Software 2, Software 3, Software 4,\\
                        & Software 5, Software 6, Software 7, etc. etc.
\end{tabular}
\end{document}
David Carlisle
  • 757,742
jub0bs
  • 58,916
3

You want a modified description environment.

\documentclass{article}
\usepackage[pass,showframe]{geometry}% just for the example

\usepackage{enumitem}

\newlength{\mydesclen}
\newenvironment{mydesc}[1]
 {\settowidth{\mydesclen}{\textbf{#1} --- }%
  \newcommand{\mitem}[1]{\item[\normalfont\textbf{##1} --- ]}%
  \begin{description}[
    labelwidth=\mydesclen,
    leftmargin=\mydesclen,
    labelsep=0pt,
    align=right]}
 {\end{description}}

\begin{document}
\begin{mydesc}{Hardware}

\mitem{Software} MS Office Powerpoint, Software 1, Software 2, Software 3,
   Software 4, Software 5, Software 6, Software 7, etc. etc.

\mitem{Hardware} Mac, Dell, Casio, Hewlett \& Packard, long long long long
  long long long long long long long text

\end{mydesc}
\end{document}

It would be possible to avoid specifying the widest term.

enter image description here

\documentclass{article}
\usepackage[pass,showframe]{geometry}% just for the example

\usepackage{enumitem,environ}

\newlength{\mydesclen}
\NewEnviron{mydesc}{%
  \global\mydesclen=0pt
  \setbox0=\vbox{\hbadness=10000
    \def\mitem##1{\sbox2{\textbf{##1} --- }%
      \ifdim\wd2>\mydesclen \global\mydesclen=\wd2 \fi}
    \BODY}
  \def\mitem##1{\item[\normalfont\textbf{##1} --- ]}%
  \begin{description}[
    labelwidth=\mydesclen,
    leftmargin=\mydesclen,
    labelsep=0pt,
    align=right]
  \BODY
  \end{description}}

\begin{document}
\begin{mydesc}

\mitem{Software} MS Office Powerpoint, Software 1, Software 2, Software 3,
   Software 4, Software 5, Software 6, Software 7, etc. etc.

\mitem{Hardware} Mac, Dell, Casio, Hewlett \& Packard, long long long long
  long long long long long long long text

\end{mydesc}
\end{document}
egreg
  • 1,121,712