# A bounding box around the elements of a document

I want to draw bounding box around the elements of my documents, say a text content, an image or some heading.

Additionally, I want that none of the elements should change there position on the document as a result of bounding box, i.e., they should remain exactly at the same position where they were before and after the placement of bounding box.

How should I go about doing this?

I don't want to manually define a box for a set of elements, as that would require me to do lot of labour for different boxes in different parts of documents.

Before the bounding box placement :

After the bounding box placement :

I tried using the tbox package using the following lines of code :

\newtcolorbox{shadedBack}{colback=shadepink, sharp corners=southwest, colframe=shadepink, boxrule=0pt,arc=0pt,boxsep=2pt,left=2pt,right=2pt,leftrule=1pt}

\pinkbullet Une phrase est \textbf{une suite de mots qui a un sens.} \\
\textbf{Elle commence par une majuscule et se termine par un point (. ! ? ...).}\\
\htab[0.75cm]  \textit{Exemple:} Elle apprend le norvégien pour parler à son correspondant.
\vspace{0.5mm}

\pinkbullet Quand une phrase contient \textbf{un verbe} au moins, on dit que c'est une \textbf{phrase verbale.} \\
\htab[0.75cm]  \textit{Exemples:} La mère \textcolor{bullet_dark_pink}{s'inquiète} pour son fils. Àvous de \textcolor{bullet_dark_pink}{jouer} !

\vspace{0.5mm}

\pinkbullet Quand une phrase ne contient \textbf{pas de verbe}, on dit que c'est une \textbf{phrase non verbale.} \\
\htab[0.75cm]  \textit{Exemple:} Sans blague !\\


But the formatting of the text before and after the tbox changed. See the following images:

• Do you mean you want to draw something like a blue box around the word "je m'exerce"? – Michael Fraiman Jun 26 '18 at 9:51
• No I want to draw a box as I have drawn on question no 5. I have edited the question and I think it is more clear now. – JVJ Jun 26 '18 at 9:57
• It seems that you asked a lot of questions regarding formatting of an exercise book. You should show some efforts and ask clear questions about what you want. You should also search this site for similar questions before asking. Package tcolorbox will help you with the box. – Michael Fraiman Jun 26 '18 at 10:00
• "I want that none of the elements should change there position on the document as a result of bounding box, i.e., they should remain exactly at the same position where they were before and after the placement of bounding box." I tried tcolor box, but it slightly modifies the position of elements being rendered, thanks for the suggestion anyways. – JVJ Jun 26 '18 at 10:04
• Then you should post a code with a tcolorbox and ask how to make it not influence the position. – Michael Fraiman Jun 26 '18 at 10:10

A default tcolorbox has some margins around the text, and box borders also add some width and height to its contents, therefore it's normal that your text moves when is included a tcolorbox.

But you can try with a minimal tcolorbox, which reduces to zero all margins around the text:

\documentclass[twocolumn]{article}
\usepackage[most]{tcolorbox}
\usepackage{lipsum}

\newtcolorbox{minbox}[1][]{
enhanced,
breakable,
size=minimal,
before={\par\smallskip\parindent=0pt},
after={\par},
before upper={\parindent10pt},
colback=red!30,
#1
}

\begin{document}

\lipsum[1]

\begin{minbox}
\lipsum[2]
\end{minbox}

\begin{minbox}[colback=green!20]
\lipsum[3-4]
\end{minbox}

\begin{minbox}
\lipsum[5]
\end{minbox}

\end{document}


Update

If OP insists in not composing the text with desired boxes and backgrounds but adding them later on, the only solution I know is to use eso-pic and add backgrounds by hand, one by one, like in following example. I won't like to do so much boring and inprecise work.

eso-pic package draws a grid on background and AddToShipoutPictureBG* allows us to define specific backgrounds for each page. As I don't know how to draw and fill rectangles with picture, I've used TikZ. One tha backgrounds are on their place, colorgrid option is deleted and we get the desired result.

\documentclass[twocolumn]{article}
\usepackage{lipsum}
\usepackage[colorgrid,gridunit=mm]{eso-pic}
\usepackage{tikz}
\begin{document}