1

I am having trouble with indenting. I would like a non-indented paragraph to be followed by an indented multi-line example. That example should have a hanging indent. I've tried using the hanging package, with no success. Here is an MWE:

\documentclass[letterpaper,12pt,titlepage,openright,twoside,final]{book}

\begin{document}

\noindent Words are here, and they form a paragraph. Words are here, and they form a paragraph. Words are here, and they form a paragraph. Words are here, and they form a paragraph. Words are here, and they form a paragraph. \\

{\textbf{Example}}: Suppose this is an example. I would like the example to be indented (yay, it is!), and I would like the text on the next line of the example to line up with the letter ``S" in ``Suppose" at the beginning of the first sentence in the example. \\

\noindent Words are here, and they form a paragraph. Words are here, and they form a paragraph. Words are here, and they form a paragraph. Words are here, and they form a paragraph. Words are here, and they form a paragraph.
\end{document}
1

You can use a description list:

\begin{description}[leftmargin=!,labelwidth=\widthof{\bfseries Example:}]
  \item [Example:] Suppose this is an example. I would like ... 
\end{description}

enter image description here

If you also want to indent the entire Example block you can use labelindent. For instance, with

\begin{description}[leftmargin=!,labelwidth=\widthof{\bfseries Example:},labelindent=2.0em]
  \item [Example:] Suppose this is an example. I would like ... 
\end{description}

you get:

enter image description here

Code:

\documentclass[letterpaper,12pt,titlepage,openright,twoside,final]{book}

\usepackage{enumitem}
\usepackage{calc}

\begin{document}

\noindent Words are here, and they form a paragraph. Words are here, and they form a paragraph. Words are here, and they form a paragraph. Words are here, and they form a paragraph. Words are here, and they form a paragraph. 

\begin{description}[leftmargin=!,labelwidth=\widthof{\bfseries Example:}]
  \item [Example:] Suppose this is an example. I would like the example to be indented (yay, it is!), and I would like the text on the next line of the example to line up with the letter ``S" in ``Suppose" at the beginning of the first sentence in the example. 
\end{description}

\noindent Words are here, and they form a paragraph. Words are here, and they form a paragraph. Words are here, and they form a paragraph. Words are here, and they form a paragraph. Words are here, and they form a paragraph.
\end{document}
  • Only issue: "Example" is not indented. How can this be fixed? – StatsSorceress Sep 20 at 18:27
  • You can use labelindent=2.0em, for example. – Peter Grill Sep 20 at 18:27
  • Thank you Peter. Could you please include that in the code? – StatsSorceress Sep 20 at 18:29
  • Wonderful, thank you again! – StatsSorceress Sep 20 at 18:35
  • Sir --Kindly let me know how to indent the first line only in front of label"example" so that " Suppose " is shifted right by say 1cm--Thanks – js bibra Nov 9 at 6:46
1

You should never need \indent or \noindent in a document, the layout of paragraphs should be a document wide setting, not something to secify each time. Also never end a paragraph with \\ (LaTeX warns about that in the log)

enter image description here

\documentclass[letterpaper,12pt,titlepage,openright,twoside,final]{book}
\usepackage{parskip}
\newenvironment{example}
               {%
\sbox0{\textbf{example}: }%
\list{}{\labelwidth\wd0 \leftmargin\wd0 \labelsep 0pt }
             \item[\usebox0]}
               {\endlist}

\begin{document}

Words are here, and they form a paragraph. Words are here, and they form a paragraph. Words are here, and they form a paragraph. Words are here, and they form a paragraph. Words are here, and they form a paragraph.%no! \\

\begin{example}
Suppose this is an example. I would like the example to be indented (yay, it is!), and I would like the text on the next line of the example to line up with the letter ``S'' in ``Suppose'' at the beginning of the first sentence in the example.%no!! \\
\end{example}

Words are here, and they form a paragraph. Words are here, and they form a paragraph. Words are here, and they form a paragraph. Words are here, and they form a paragraph. Words are here, and they form a paragraph.
\end{document}
  • Sir --Kindly let me know how to indent the first line only in front of label"example" so that " Suppose " is shifted right by say 1cm--Thanks – js bibra Nov 9 at 6:45
1

Another possibility uses the linegoal package, which measures the remaining space on the line at its point of insertion:

\documentclass[letterpaper,12pt,titlepage,openright,twoside,final]{book}
\usepackage{hanging}
\usepackage{linegoal}

\begin{document}

\noindent Words are here, and they form a paragraph. Words are here, and they form a paragraph. Words are here, and they form a paragraph. Words are here, and they form a paragraph. Words are here, and they form a paragraph. \\

\textbf{Example}: \parbox[t]{\linegoal}{Suppose this is an example. I would like the example to be indented (yay, it is!), and I would like the text on the next line of the example to line up with the letter ``S" in ``Suppose" at the beginning of the first sentence in the example. \\h. Words are here, and they form a paragraph. \\}

\noindent Words are here, and they form a paragraph. Words are here, and they form a paragraph. Words are here, and they form a paragraph. Words are here, and they form a paragraph. Words are here, and they form a paragraph.

\end{document} 

enter image description here

  • Sir --Kindly let me know how to indent the first line only in front of label"example" so that " Suppose " is shifted right by say 1cm--Thanks – js bibra Nov 9 at 6:45

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.