0

I would like to adjust the position of a box created with tcolorbox by respecting the values of the horizontal margin on each of the two sides. For instance : I would like to avoid the box to appear like this :

enter image description here

I have specified width = \textwidth but I don't understand why the result appears like this...

Here is my code :

\documentclass{article}

\usepackage{geometry}
\geometry{hmargin=1cm,vmargin=1.5cm}
\usepackage{pgf, tikz, adjustbox}
\usepackage{tcolorbox}

\begin{document}

\tcbset{colback=red!5!white,colframe=red!75!black,fonttitle=\bfseries, width = \textwidth}
\begin{tcolorbox}[before=\adjustbox{valign=t}\bgroup, after=\egroup]
\textbf{A retenir}
Bla-bla-bla
\end{tcolorbox}

\end{document}

I have specified the margin size with the line \geometry{hmargin=1cm,vmargin=1.5cm} but it seems like it's not respected by the box adjustment.

Thank you for your help,

Best regards.

1 Answer 1

1

The problem is not the tcolorbox but your geometry specifications and your width specification. This is how the ouput looks:

enter image description here

From the image you can see that the box is indeed as wide as the text, but has a \parindent at the start. To fix this, simply change the width to width = \linewidth-\parindent. This produces:

enter image description here

To fix get rid of the \parindent to the left of the box, simply use \noindent before the box environment.

enter image description here

Also: here is a link to specifications of geometry: https://www.overleaf.com/learn/latex/Page_size_and_margins

4
  • Thank you @Vebjorn : actually I have already seen this documentation but didn't understand it well. For instance the last figure of the \layout shows different dimensions but what is \geometry{hmargin=1cm,vmargin=1.5cm} really fixing ? Is it n°3 \oddsidemargin or something else ? Also what is \parindent please ?
    – Waxler
    May 21, 2022 at 18:28
  • \parindent is the space (indent) on the first line in the paragraph. I guess hmargin is the horisontal margin (on both sides, total horisontal margin) and vmargin is the vertical margin (on top and bottom). I use left= and right= to fix the margins.
    – Vebjorn
    May 21, 2022 at 18:37
  • How do you think it would be possible to have the same values on both sides of the box equal to the values of hmargin ? (instead of putting parindent)
    – Waxler
    May 21, 2022 at 18:39
  • Try \noindent before the box. See this question: tex.stackexchange.com/questions/337771/…
    – Vebjorn
    May 21, 2022 at 18:49

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .