我使用tcolorbox
es,有时希望它们成为较大段落的一部分,也就是说,我希望后面的文本tcolorbox
不缩进。但是,\noindent
和都\@afterheading
存在一些缺陷(请参阅 MWE 中的注释)。
如何才能避免出现tcolorbox
这些缺陷?我也不想失去默认提供的良好间距(即/tcb/beforeafter skip balanced
)。
\documentclass{article}
\usepackage{tcolorbox}
\makeatletter
% This leads to extra spacing before a heading.
%\AddToHook{env/tcolorbox/after}{\noindent\ignorespaces}
% This leads to reduced spacing before a heading as well as
% not allowing new paragraphs after the environment.
% It also prevents page breaks, which I do not want.
%\AddToHook{env/tcolorbox/after}{\@afterheading}
\begin{document}
\section{Indentation after Boxes}
Here's a box followed by a heading.
\begin{tcolorbox}
This box is followed by a heading.
\end{tcolorbox}
\subsection{A Heading}
Here's a box that is part of a paragraph
\begin{tcolorbox}
This box should not lead to indentation of the following line.
\end{tcolorbox}
and should not cause indentation in this line.
And here's a box at the end of its paragraph.
\begin{tcolorbox}
This box is followed by a new, indented paragraph.
\end{tcolorbox}
This is a new paragraph.
\end{document}
答案1
\@endparenv
将每个列表环境都使用的附加到/tcb/after
似乎有效。
更新:对于可破坏的盒子,增加了一些实验尝试。
\documentclass{article}
\usepackage{lipsum}
\usepackage{tcolorbox}
\tcbuselibrary{hooks, breakable}
\makeatletter
\tcbset{
after app={%
\ifx\tcb@drawcolorbox\tcb@drawcolorbox@breakable
\else
% add only when not breakabel
\@endparenv
\fi
}
}
% for breakable
\appto\tcb@use@after@lastbox{\@endparenv\@doendpe}
\makeatother
\begin{document}
\section{Indentation after Boxes}
Here's a box followed by a heading.
\begin{tcolorbox}
This box is followed by a heading.
\end{tcolorbox}
\subsection{A Heading}
Here's a box that is part of a paragraph
\begin{tcolorbox}[title=Unbreakable]
This box should not lead to indentation of the following line.
\end{tcolorbox}
and should not cause indentation in this line.
Here's a box that is part of a paragraph
\begin{tcolorbox}[title=Breakable but not broken, breakable]
This box should not lead to indentation of the following line.
\end{tcolorbox}
and should not cause indentation in this line.
Here's a box that is part of a paragraph
\begin{tcolorbox}[title=Breakable and broken, breakable]
\lipsum[1-2]
\end{tcolorbox}
and should not cause indentation in this line.
And here's a box at the end of its paragraph.
\begin{tcolorbox}
This box is followed by a new, indented paragraph.
\end{tcolorbox}
This is a new paragraph.
\end{document}