So I've been looking to expand on the following bit of code (a hack to not screw up the margins when using oversized figures):
\noindent\makebox[\textwidth]{%
\begin{tabularx}{1.5\textwidth}{XX}
\blindtext & \blindtext
\end{tabularx}
}
I wanted to turn this into an environment, so was thinking of doing the following:
\newenvironment{figurehack}{\noindent\makebox[\textwidth]\bgroup}{\egroup}
This throws a strop, LaTeX decides to insert the "missing" brace. So to see if this was a newenvironment quirk, I tried the following bit of code:
\noindent\makebox[\textwidth]\bgroup%
\begin{tabularx}{1.5\textwidth}{XX}
\blindtext & \blindtext
\end{tabularx}
\egroup
LaTeX once again tries to insert the "missing" brace. Any suggestions how I can resolve this?
Best Answer
You can only use
\bgroup
and\egroup
as a replacement for{
and}
if LaTeX is expanding the content like it does for low-level boxing commands, but not when it is looking for an macro argument. The\makebox
macro reads the content as argument not as box, so your attempt doesn't work. I wrote therealboxes
package which provides variants of all\...box
macros which read the content as real boxes using my other packagecollectbox
. Simply loadrealboxes
and use\Makebox
instead:Also have a look on my
adjustbox
package which provides an\adjustbox
macro andadjustbox
environment. It also allows\bgroup
/\egroup
and provides many options which can be easily combined. A\makebox[\textwidth]
(which by default centers the content) can be done using\adjustbox{center=\textwidth}
. The\textwidth
is already the default value, so\adjustbox{center}
would be enough.