不,不是的。不管加不加noindent和hangindent=4em都没有缩进。以下是同文章内其他效果相同的结果的代码和图片:
documentclass[utf8,oneside]{book}%LaTex的book类型中,目录及chapter前自动插入空白页面,解决方案:加入oneside选项
usepackage{titletoc}
usepackage{titlesec}
usepackage[dvipsnames]{xcolor}
usepackage{ctexcap}
usepackage[b5paper,text={125mm,195mm},centering,left=1in,right=1in,top=1in,bottom=1in]{geometry}
usepackage[]{geometry}
usepackage{imakeidx}
usepackage{multicol}
usepackage{graphicx}
usepackage{tcolorbox}
usepackage{lipsum}
usepackage[colorlinks,linkcolor=black, anchorcolor=blue,citecolor=green]{hyperref}
usepackage{ragged2e}
usepackage{caption}
usepackage{array}
usepackage{longtable}
captionsetup[table]{justification=raggedright, singlelinecheck=off}
makeindex
bibliographystyle{plain}
begin{document}
\newtcolorbox{graypara}{
colback=gray!20,
colframe=white,
boxrule=0pt,
left=5pt, right=5pt,
top=3pt, bottom=3pt,
arc=2pt,
before=\par\noindent,
after=\par\noindent
}
\begin{graypara}
\textbf{def best\_word(word\_list):}
\textbf{"""}
\textbf{ word\_list is a list of words.}
\textbf{Return the word worth the most points.}
\textbf{"""}
best\_word = ""
best\_points = 0
for word in word\_list: \#1
points = num\_points(word)
if points $>$ best\_points:
best\_word = word
best\_points = points
return best\_word
\end{graypara}
end{document}
另,不知道为什么在使用您推荐的方式去尝试完成我的代码时编译出现了错误,错误报告为:chapter_5.listing: 错误: 3: Improper alphabetic constant. ...sking the user for a password until it’s。可以请问一下为什么吗?谢谢
问 如何在graypara中使用缩进?