2

I currently use this code to create my boxes :

\documentclass[12pt,a4paper,french]{article}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage{tcolorbox}
\newtcolorbox{mybox}[1][]{before=\centering, hbox, drop fuzzy shadow, enhanced}
\tcbuselibrary{skins}

\begin{document}
\begin{large}
\begin{flushleft}

gfdsgsdgsd gdssssssssssssssssssssssssssffffgdsffffffffffffffffffffffffffff\\
\vspace{5mm}
\begin{mybox}
$\begin{aligned}
a\leq b \Leftrightarrow ac \leq bc
\end{aligned}$
\end{mybox}

gfdsgsdgsd gdssssssssssssssssssssssssssffffgdsffffffffffffffffffffffffffff\\
\vspace{5mm}
\begin{mybox}
$\begin{aligned}
1+1=2
\end{aligned}$
\end{mybox}

gfdsgsdgsd gdssssssssssssssssssssssssssffffgdsffffffffffffffffffffffffffff\\
\vspace{5mm}
\begin{mybox}
$\begin{aligned} 
gdssssssssssssssssssssssss
\end{aligned}$
\end{mybox}

\end{flushleft}
\end{large}
\end{document}

I'd like all my boxes to be the width of my biggest box.

How can I do that? thank you

2
  • Welcome to TeX.SX! Can you please expand the code snippet that you have posted to a full minimal working example. It is much easier to help you if we can start with some compilable code that illustrates your problem. A MWE should start with a \documentclass command, include any necessary packages and be as small as possible to demonstrate your problem. At the moment we have to guess what packages etc you are using before we can compile your code.
    – user30471
    Commented Mar 5, 2020 at 21:07
  • @Andrew Hi, I'm sorry I edited
    – Colat
    Commented Mar 5, 2020 at 21:16

1 Answer 1

3

You can do that very easily with the eqparbox package (two compilations are necessary):

\documentclass[12pt,a4paper,french]{article}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage{eqparbox}
\usepackage{tcolorbox}
\newtcolorbox{mybox}[1][]{before=\centering, hbox, drop fuzzy shadow, enhanced}
\tcbuselibrary{skins}

\begin{document}

\begin{large}
\begin{flushleft}

gfdsgsdgsd gdssssssssssssssssssssssssssffffgdsffffffffffffffffffffffffffff\\
\vspace{5mm}
\begin{mybox}
\eqmakebox[M]{$\begin{aligned}
a\leq b \Leftrightarrow ac \leq bc
\end{aligned}$}
\end{mybox}

gfdsgsdgsd gdssssssssssssssssssssssssssffffgdsffffffffffffffffffffffffffff\\
\vspace{5mm}
\begin{mybox}
\eqmakebox[M]{$\begin{aligned}
1+1=3
\end{aligned}$}
\end{mybox}

gfdsgsdgsd gdssssssssssssssssssssssssssffffgdsffffffffffffffffffffffffffff\\
\vspace{5mm}
\begin{mybox}
\eqmakebox[M]{$\begin{aligned}
gdssssssssssssssssssssssss
\end{aligned}$}
\end{mybox}

\end{flushleft}
\end{large}

\end{document} 

enter image description here

10
  • Thank you, it's working. It is not possible in only 1 compilation? On my application, two compilations will be problematic in some cases. Currently I use hspace{Xcm} but it's heavy to do...
    – Colat
    Commented Mar 5, 2020 at 21:43
  • LaTeX has to determine first which is the widest box, before setting all boxes to this width. Note that for another series, with a possibly different common width, you have to chage the eqmakebox tag (the letter M here). Maybe you could add this tag as an optional argument of the mybox environment and this construction in the definition of the environment? I don't know enough of tcolorbox to do that.
    – Bernard
    Commented Mar 5, 2020 at 21:49
  • On my app, I select random texts that I compile in latex, calling the compilation twice would slow down the program considerably. Otherwise, it's not possible to check myself the size of the biggest box and to wedge all the others on it?
    – Colat
    Commented Mar 5, 2020 at 21:51
  • 1
    You can try with \makebox[\mylength]{...}, where you define \mylength as \widthof{longest formula} (you also should add 2\fboxsep).
    – Bernard
    Commented Mar 5, 2020 at 22:01
  • 1
    In this case, you can use a code like this in the preamble: \newlength{\tcbwidth} \settowidth{\tcbwidth}{$gdssssssssssssssssssssssss$}\newtcolorbox{mybox}[1][]{before=\centering, hbox, drop fuzzy shadow, enhanced, width=\tcbwidth}..
    – Bernard
    Commented Mar 5, 2020 at 23:15

You must log in to answer this question.

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