What is graypara ?
请提供一份能体现你问题的完整代码。
「完整」指的是从\documentclass开始到\end{document}结束
就是使用之后所有段都没有了缩进
源代码
\documentclass{article}
\usepackage{tcolorbox}
\usepackage{lipsum}
\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{document}%
\lipsum[2]
\begin{graypara}%
\noindent hour = int(input('Please enter the current hour from 0 to 23: '))
\noindent if hour < 12:
\hangindent=4em
print('Good morning!')
print('Have a nice day.')
\noindent elif hour < 18:
print('Good afternoon!')
\noindent else:
print('Good evening!')
\noindent print('Have a good night.')
\end{graypara}% %注意这里后面的空行
\lipsum[2]
\end{document}这将得到:

其实是有缩进的。
一些探索
你在设置中写到:
before=\par\noindent,
after=\par\noindent,前者可以让你的整个盒子不缩进,而后者直接让你的盒子后的下一段不缩进(如果你不用空行表示新的一段的话)...
另外,你不需要写那么多的\noindent,似乎也不应该写\hangindent=4em,另外,如果要实现「代码盒子」,你可以看一下文档里的tcblistings环境,最好使用等宽字体。
我不知道你的最终目标是什么(你可以做补充),但我如果是我的话,我会修改成:
注意tcblistings中的代码会与你源代码中的缩进保持一致
\documentclass{article}
\usepackage{showframe}
\usepackage{tcolorbox}
\tcbuselibrary{listings}
\usepackage{lipsum}
\newtcblisting{graypara}{
listing only,
colback=gray!20,
colframe=white,
boxrule=0pt,arc=2pt,
left=5pt, right=5pt,
top=3pt, bottom=3pt,
before=\par\noindent,
after=\par,
}
\begin{document}%
\lipsum[2]
% 注意tcblistings中的代码会与你源代码中的缩进保持一致
\begin{graypara}
hour = int(input('Please enter the current hour from 0 to 23: '))
if hour < 12:
print('Good morning!')
print('Have a nice day.')
elif hour < 18:
print('Good afternoon!')
else:
print('Good evening!')
print('Have a good night.')
\end{graypara}
\lipsum[2]
\lipsum[2]
\end{document}




























问 如何在graypara中使用缩进?