# How to draw a frame with an “external padding”?

I want to draw a frame around a part of the text so that the margins around this part of the text are not affected.

Below is a solution with the help of tcolorbox. I've found this solution by trying-and-fixing. So, my question is: is this solution good or is there a better one? The only drawback to this solution I see is that it does not take into account the value of \parindent. This is not important for me as I intend to use this piece of code in a text where \parindent equals 0pt.

I prefer using tcolorbox than mdframed: tcolorbox seems to be better maintained. Nevertheless, any solution could be interesting for me or for future readers.

Thank you

\documentclass{article}

\usepackage{showframe}
\usepackage{tcolorbox}

\newtcolorbox{myBox}
{size = minimal, colback = red,
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}


• please have a look at the answer below -- with and without parindent -- solution at --tex.stackexchange.com/questions/200632/… – js bibra Feb 26 at 14:59
• I guess you just want to use the tcolorbox option oversize. Try \newtcolorbox{myBox}{oversize, colback = red, top = 2mm, bottom = 2mm}. For details, see the documentation. – benjamin Feb 26 at 15:06

You can use oversize option, it enlarges margins and the text is as wide as in unboxed paragraphs.

\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}


\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}

• But this restricts the margins, which is exactly what the OP does not want. – campa Feb 26 at 15:06
• was addressing the issue of parindent – js bibra Feb 26 at 15:08