我想在文本的某一部分周围画一个框,以便这部分文本周围的边距不受影响。
以下是借助 的解决方案tcolorbox
。我通过不断尝试和修复找到了此解决方案。因此,我的问题是:这个解决方案好吗或者有更好的解决方案吗?我发现这个解决方案的唯一缺点是它没有考虑到 的值。这对我来说并不重要,因为我打算在等于 的\parindent
文本中使用这段代码。\parindent
0pt
我tcolorbox
更喜欢使用mdframed
:tcolorbox
似乎维护得更好。不过,任何解决方案都可能对我或未来的读者有趣。
谢谢
\documentclass{article}
\usepackage{showframe}
\usepackage{tcolorbox}
\def\exteriorPadding{3mm}
\newtcolorbox{myBox}
{size = minimal, colback = red,
leftrule = -\exteriorPadding, left = \exteriorPadding,
rightrule = -\exteriorPadding, right = \exteriorPadding,
top = 2mm, bottom = 2mm}
\begin{document}
Test: This is a test. This is a test. This is a test. This is a test. This is a test. This is a test. This is a test. This is a test. This is a test. This is a test. This is a test. This is a test. This is a test. This is a test. This is a test. This is a test. This is a test. This is a test. This is a test. This is a test. This is a test. This is a test. This is a test. This is a test. This is a test. This is a test. This is a test. This is a test.
\begin{myBox}
Test: This is a test. This is a test. This is a test. This is a test. This is a test. This is a test. This is a test. This is a test. This is a test. This is a test. This is a test. This is a test. This is a test. This is a test. This is a test. This is a test. This is a test. This is a test. This is a test. This is a test. This is a test. This is a test. This is a test. This is a test. This is a test. This is a test. This is a test. This is a test.
\end{myBox}
\end{document}
答案1
您可以使用oversize
选项,它可以放大边距,并且文本与非装箱段落一样宽。
\documentclass{article}
\usepackage{showframe}
\usepackage{tcolorbox}
\newtcolorbox{myBox}
{colback = red, top=2mm, bottom=2mm, boxrule=0pt,
oversize}
\begin{document}
Test: This is a test. This is a test. This is a test. This is a test. This is a test. This is a test. This is a test. This is a test. This is a test. This is a test. This is a test. This is a test. This is a test. This is a test. This is a test. This is a test. This is a test. This is a test. This is a test. This is a test. This is a test. This is a test. This is a test. This is a test. This is a test. This is a test. This is a test. This is a test.
\begin{myBox}
Test: This is a test. This is a test. This is a test. This is a test. This is a test. This is a test. This is a test. This is a test. This is a test. This is a test. This is a test. This is a test. This is a test. This is a test. This is a test. This is a test. This is a test. This is a test. This is a test. This is a test. This is a test. This is a test. This is a test. This is a test. This is a test. This is a test. This is a test. This is a test.
\end{myBox}
\end{document}
答案2
\documentclass{article}
\usepackage{lipsum}
\usepackage[most]{tcolorbox}
\begin{document}
\texttt{With parindent=0pt}
%\showthe\parindent %%,---- find \parindent
\begin{tcolorbox}[breakable,enhanced,before upper={\parindent0pt}]
\lipsum[9]
\end{tcolorbox}
\texttt{With parindent=15pt}
\begin{tcolorbox}[breakable,enhanced,before upper={\parindent15pt}]
\lipsum[9]
\end{tcolorbox}
\lipsum[8]
\end{document}