5

enter image description here


How can I apply custom length of indent by giving a "precise word length" instead of estimate numbers under trial and error e.g. x pt or x mm?

Mico
  • 506,678
Howard
  • 377
  • 2
  • 10
  • For a single paragraph \settowidth{\hangindent}{\textbf{A Shot Head: }} will work. – John Kormylo Sep 29 '15 at 04:00
  • possible duplicate http://tex.stackexchange.com/questions/263765/tabbing-from-the-beginning-of-a-line – CroCo Sep 29 '15 at 04:01
  • 2
    @JohnKormylo - Using the \settowidth approach isn't quite sufficient: If the right-hand edges of the paragraph are justified, the actual head text has to be encased in an \mbox in order to "freeze" the widths of any interword spaces. – Mico Sep 29 '15 at 05:25

1 Answers1

3

You could use the \settowidth macro to set the value of the \hangindent length parameter to the width of a chosen string.

Note: If you use hanging indentation, and assuming the right-hand edges of the paragraph are justifed, it's necessaryto encase the head element -- "A short head", "A much longer head", etc -- in an \mbox in order to keep LaTeX from stretching or shrinking any spaces that may occur in the lead text. Placing the head element in an \mbox "freezes" the widths of the interword spaces.

enter image description here

\documentclass{article}
\usepackage{parskip} % no \parindent, \non-zero parskip

\newcommand\dummytext{This is a long sentence that will extend to the second line. I want the second line indented by the length of the head words.}

\begin{document}

\settowidth{\hangindent}{\textbf{A short Head: }}
\mbox{\textbf{A short Head: }}\dummytext

\settowidth{\hangindent}{\textbf{A much longer Head: }}
\mbox{\textbf{A much longer Head: }}\dummytext

\settowidth{\hangindent}{\textbf{Head: }}
\mbox{\textbf{Head: }}\dummytext

\end{document}
Mico
  • 506,678