# Hanging Indents / Text Wrapping

I'm trying to implement a command to be used in place of the itemize/enumerate environments. The idea is that I want to have a command (\detail), which can be used to construct an itemized list without being contained in an environment. The problem I'm having is that when a line is longer than the page width and consequently wraps to the next line, I don't seem to have any control over the indentation of the wrapped text. I've tried the hanging package and \hangindent, but haven't had much luck.

I've included a minimum example below and the output that I get when compiled. Ideally, I would like the wrapped text to be indented such that the first word on the second line aligns with the first word of the first line.

\documentclass{article}
\newcommand{\detail}[1]{-- {#1}}

\begin{document}
\detail{This is a detail.}\\
\detail{This is a detail that has too many words in it and consequently runs onto the next line of the page, and I want it to have a hanging indent.}
\end{document}


\documentclass{article}
\def\D{\par\noindent\makebox[1em][l]{-- }\hangindent1em}
\begin{document}
\D This is a detail
\D This is a detail that has too many words in it and consequently runs onto The next line of the page, and I want it to have a hanging indent.
\end{document}


• Ok, so this aligns perfectly whereas the previous answer did not. Can you explain to me why this works better? – Kevin Apr 20 '15 at 18:13
• @Kevin I think that is only a optical effect because the shape of the "T". In the answer of Harish Kumar, change the "next" of the last line by "Text". Both "T" are now perfectly aligned. Try only a text with \noindent T\par \noindent n\par and you will see that n seem also here misaligned with respect the "T", but both characters are just in the margin! – Fran Apr 20 '15 at 18:45
• It's not an illusion. My actual document has two capital "M"s, one directly beneath the other. With Harish Kumar's answer, the "M"s do not align, but with yours they do. – Kevin Apr 20 '15 at 18:57
• @Kevin I needed a zoom at 400% to note that, but you are right. I do not know why the result is not exactly the same. – Fran Apr 20 '15 at 19:53
• Why is the wrapped line starting with a capital T? – Ibn Saeed Apr 21 '15 at 3:36
\documentclass{article}
\newcommand{\detail}[1]{\par\noindent\hangindent=\mylen\hangafter1-- #1}
\newlength{\mylen}
\settowidth{\mylen}{-- }

\begin{document}
\detail{This is a detail.}
\detail{This is a detail that has too many words in it and consequently runs onto the next line of the page, and I want it to have a hanging indent.}
\end{document}


• Awesome! That's almost perfect. For some reason, the alignment is just a hair off, which becomes really apparent when a hanging line starts with the same letter: i.snag.gy/Zb3N5.jpg – Kevin Apr 20 '15 at 2:21
• @Kevin My eyes are pretty bad. Try with \settowidth{\mylen}{--\space} – user11232 Apr 20 '15 at 2:26
• Nope, that has the same effect. I tried with other bullet icons in case it was the en dash that was messing it up, but they still don't come out exactly aligned. – Kevin Apr 20 '15 at 2:32
• @HarishKumar -- the space after the dash will be included in the justification process, so unless all the spaces after the justification are absolutely equal to the "natural" width, that initial space will cause the first letter of the text to be out of line with the hanging indent. put it in a box. (the \settowidth works, because that will use the "natural" width of the space.) – barbara beeton Apr 21 '15 at 16:35
• @barbarabeeton I doubted that. Thanks. :-) – user11232 Apr 21 '15 at 23:19
\documentclass{article}
\newcommand{\detail}[1]{\par\noindent\hangindent=\mylen\hangafter1--\,\,#1}
\newlength{\mylen}
\settowidth{\mylen}{--\,\,}

\begin{document}