I'm sorry if I lack the basics of tex and macro definitions, I only started to get into it.
My concrete question is how to get Custom margins for figure in LaTeX, in particular how to Center figure that is wider than \textwidth. But I want this setting defined in a macro.
So this is why I ask a more general question about macro syntax: how to nest the content of my environment inside a command? I thought I just needed to replace { ... } by \bgroup ... \egroup but
my attempt at adapting the "makebox" approach in a \renewenvironment failed:
\let\origfig=\figure
\let\endorigfig=\endfigure
\renewenvironment{figure}[1][]{%
\origfig
\noindent\makebox[\textwidth]\bgroup\centering
}{
\egroup\endorigfig
}
throws
! Missing } inserted.
<inserted text>
}
P.S: as for this specific float width question, I'll happily use packages that get the job done, like floatrow (but I haven't managed to produce the desired result yet).
P.P.S: I want to redefine the table environment this way as well.
EDIT. I added a minimal example based on @egreg's answer:
\documentclass{article}
% Install package "mwe" to get the example image.
\usepackage{graphicx}
% From: https://tex.stackexchange.com/a/541576
\makeatletter
\expandafter\def\expandafter\@floatboxreset\expandafter{\@floatboxreset\centering}
\makeatother
\begin{document}
% To visualise the text margins:
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
\begin{figure}[h]
\includegraphics[width=1.2\linewidth, height=0.1\textheight]{example-image-a.png}
\end{figure}
2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2
2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2
2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2
\end{document}
\bgroupto delimit a macro argument\noindent\makebox[\textwidth]\bgroupcan not work (not specific to\makebox) – David Carlisle Apr 30 '20 at 15:42environinstead? – PlasmaBinturong Apr 30 '20 at 15:53\makeboxin this way, it means that you will get no warning if your figures/tables overflow the text block or even the page. Getting warnings if the output is not visible is a feature not a problem to be solved. – David Carlisle Apr 30 '20 at 15:56