3

I have already asked a similar question but I think that my request was unclear. I have created a box using tcolorbox and I want to adjust it in order to fit the length of my "normal" text (outside of item list). in the image below : I want the red box to be aligned on the red line on the left side and same on the right side.

enter image description here

\documentclass{article}

\usepackage{geometry}
\geometry{hmargin=1cm,vmargin=1.5cm}
\newcommand{\gap}{\vspace{0.5cm}} 
\usepackage{parskip}

\usepackage{enumitem}
\usepackage{pgf, tikz, adjustbox}
\usepackage{tcolorbox}

\begin{document}

\subsubsection{Conditions limites}

\begin{enumerate}[label=\Alph*)]
\item \textbf{En $i=1$}

\tcbset{colback=red!5!white,colframe=red!75!black,fonttitle=\bfseries, width = \linewidth-\parindent}
%
\begin{tcolorbox}[before upper={\parindent0em}]
\textbf{A retenir}
\[
h(x) = \left(h_N - h_{\infty} \right) e^{\frac{(L-x)}{\sqrt{2}}} \left[\cos \left(\frac{x}{\sqrt{2}}\right) \cos \left(\frac{L}{\sqrt{2}}\right)+ \sin \left(\frac{x}{\sqrt{2}}\right) \sin \left(\frac{L}{\sqrt{2}}\right) \right] + h_{\infty}
\]
\end{tcolorbox}
\end{enumerate}

\end{document}

A user advised me to specify the width by writing : width = \linewidth-\parindent} but it adjusts the "right side" only of my box. Now I want to do it for the left side but I don't know the procedure.

I was advised to use : \usepackage{parskip} but it didn't work as well.

Could someone help me please ?

Thank you,

2 Answers 2

4

The simplest, in my opinion, would be to end the enumerate environment before the \tcolorbox, and to use the resume* key when you want to continue the environment:

    \documentclass{article}

    \usepackage[showframe]{geometry}
    \geometry{hmargin=1cm,vmargin=1.5cm}
    \newcommand{\gap}{\vspace{0.5cm}}
    \usepackage{parskip}

    \usepackage{enumitem}
    \usepackage{pgf, tikz, adjustbox}
    \usepackage{tcolorbox}

    \begin{document}

    \subsubsection{Conditions limites}

    \begin{enumerate}[label=\Alph*)]
    \item \textbf{En $i=1$}
    \end{enumerate}]
    \tcbset{colback=red!5!white,colframe=red!75!black,fonttitle=\bfseries, width = \linewidth-\parindent}
    %
    \begin{tcolorbox}[before upper={\parindent0em}]
    \textbf{A retenir}
    \[
    h(x) = \left(h_N - h_{\infty} \right) e^{\frac{(L-x)}{\sqrt{2}}} \left[\cos \left(\frac{x}{\sqrt{2}}\right) \cos \left(\frac{L}{\sqrt{2}}\right)+ \sin \left(\frac{x}{\sqrt{2}}\right) \sin \left(\frac{L}{\sqrt{2}}\right) \right] + h_{\infty}
    \]
    \end{tcolorbox}

    \end{document} 

enter image description here

3

This is the expected behavior, since you are writing the box inside a list. However, if you insist on having a "full width" box, then you probably want to use the key spread sidewards. Since here your horizontal margin is even on both sides (hmargin=1cm), spread sidewards = 1cm will do the job.

\documentclass{article}

\usepackage{geometry}
\geometry{hmargin=1cm,vmargin=1.5cm}
\usepackage{parskip}

\usepackage{enumitem}
\usepackage{tcolorbox}

\begin{document}

\subsubsection{Conditions limites}

\begin{enumerate}[label=\Alph*)]
\item \textbf{En $i=1$}
\begin{tcolorbox}[colback=red!5!white, colframe=red!75!black, spread sidewards = -1cm]
    \textbf{A retenir}
    \[
    h(x) = \left(h_N - h_{\infty} \right) e^{\frac{(L-x)}{\sqrt{2}}} \left[\cos \left(\frac{x}{\sqrt{2}}\right) \cos \left(\frac{L}{\sqrt{2}}\right)+ \sin \left(\frac{x}{\sqrt{2}}\right) \sin \left(\frac{L}{\sqrt{2}}\right) \right] + h_{\infty}
    \]
    \end{tcolorbox}
\end{enumerate}

\end{document}

enter image description here

1
  • Thank you for your help !
    – Wiss
    May 22 at 14:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.