0

I would like to write a text like this:

Text: This is a paragraph which is so long that it has a linebreak But the indent should be
      set after \phantom{Text: }.

How can I do that? How is it possible when writing normal text – and how can I do this with, for example, figure captions (with variable lengths (e.g, Figure 1: , …, Figure 10: , etc.))?

Nemgathos
  • 545
  • 3
  • 15
  • 1
    For captions using the caption package, use \captionsetup{format=hang}. For normal text (single paragraph) use \hangindent=\widthof{...} (calc package). – John Kormylo Nov 28 '17 at 21:45
  • And this solves my other problem. I would like to give you an upvote, but the new Firefox (combined with NoScript) does not allow me to do this. But I will give you an upvote as soon as I can. – Nemgathos Nov 28 '17 at 21:56
  • @JohnKormylo Please describe how to use \hangindent=\widthof{...} properly. It does not seem to work. marmot’s solution, however, works. – Nemgathos Nov 28 '17 at 22:00

3 Answers3

2

Note: \caption seems to like \blindtext better than \lipsum. Also, \hangindent does not stop normal paragraph indentation.

\documentclass{article}
\usepackage{calc}
\usepackage{blindtext}
\usepackage{caption}

\newlength{\tempdima}

\begin{document}

\setlength{\hangindent}{\widthof{Test: }}
\noindent Test: \blindtext

\sbox0{Test: }%
\hangindent=\wd0
\noindent\box0\blindtext

\settowidth{\tempdima}{Test: }
\hangindent=\tempdima
\noindent Test: \blindtext

\begin{figure}[htp]
\captionsetup{format=hang}
\caption{\blindtext}
\end{figure}

\end{document}
John Kormylo
  • 79,712
  • 3
  • 50
  • 120
  • \widthof is supported by package calc. The support is added to the macros \setlength, \addtolength: \setlength{\hangindent}{\widthof{Test: }}. It does not work inside plain register assignments or eTeX's \dimexpr. – Heiko Oberdiek Nov 28 '17 at 22:35
  • @HeikoOberdiek - Vielen Dank! Have incorporated your solution. – John Kormylo Nov 28 '17 at 22:40
1

For normal text, I would use a description instead. If the vertical space above or the bold font of "Text" bother you, these can be changed.

As also noted by John Kormylo: To make a caption behave like this, the caption package offers a hanging format.

\documentclass{article}

\usepackage{lipsum}
\usepackage{graphicx}
\usepackage[format=hang]{caption}

\begin{document}
\section{Test}

\lipsum[1]

\begin{description}
\item[Text] \lipsum[2] 
\end{description}

\begin{figure}[htbp]
    \centering
    \includegraphics[width=.5\textwidth]{example-image} 
    \caption{long caption text that spans more than one line long caption text that spans more than one line long caption text that spans more than one line}
\end{figure}

\end{document}

enter image description here

1

You can use the hanging package, a LaTeX interface for the plain TeX \hangindent=...\hangafter=... construct.

The package defines a \hangingpara command and a hangingparas environment. Demo:

\documentclass{book}
\usepackage{enumitem}
\usepackage{calc}
\usepackage{hanging}
\usepackage{lipsum}
\newlength{\myhangindent}

\begin{document}

\settowidth{\myhangindent}{Text: }

\hangpara{\myhangindent}{1}%
Text: This is a paragraph which is so long that it has a linebreak at its end. But the indent
      should be set after \phantom(Text: ).

    \begin{hangparas}{\myhangindent}{1}%
\lipsum[10-12]
\end{hangparas}

\end{document} 

enter image description here

Bernard
  • 271,350