我在缩进方面遇到了麻烦。我希望一个非缩进的段落后面跟着一个缩进的多行示例。该示例应该有一个悬挂缩进。我试过使用该hanging
包,但没有成功。这是一个 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
您可以使用description
列表:
\begin{description}[leftmargin=!,labelwidth=\widthof{\bfseries Example:}]
\item [Example:] Suppose this is an example. I would like ...
\end{description}
如果你还想缩进整个例子块,您可以使用labelindent
。例如,
\begin{description}[leftmargin=!,labelwidth=\widthof{\bfseries Example:},labelindent=2.0em]
\item [Example:] Suppose this is an example. I would like ...
\end{description}
你得到:
代码:
\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}
答案2
您永远不需要\indent
或\noindent
在文档中,段落的布局应该是文档范围的设置,而不是每次都要指定的东西。也永远不要用 结束段落\\
(LaTeX 在日志中对此发出警告)
\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}
答案3
另一种可能性是使用该linegoal
包,它测量插入点处的线路剩余空间:
\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}