# Set global margins (width) for pictures - different than text margins

I have produced my pdf output from tex file and noticed that my pictures are not "correctly" included - their left margin corresponds to the left margin of the regular text, but the right margin in beyond my control and stands out:

To address this problem, I would like to make all icnluded pictures be centered and NOT be subjected to any text margin settings (they may exceed text margins, but symmetrically). Moreover, in my case, it must be done via some global options at the beginning of the document (NOT: in the document body, e.g. within includegraphics section).

Thank you in advance for any suggestions!

• Your picture is too wide for the page: centring a picture that 'fits' is easy enough Feb 26 '14 at 17:47
• you can use \centering in the figure and use \width=1\textwidth in the square brackets after \includegraphics. If you need something global, you can define a macro using \def to replace the usual \includegraphics.
– yoki
Feb 26 '14 at 17:53
• I am also wondering what happened to second image on the right margin (with 'RStudio' title)?
– user31729
Feb 26 '14 at 18:09
• (Well, on the picture I included in my post there is one image, which consists of two "Paint-sticked" screen shoots ;) ) Feb 27 '14 at 8:17

I save (\let) a copy of \includegraphics to \svincludegraphics and then redefine it with

\renewcommand\includegraphics[2][]{\makebox[0pt]{\svincludegraphics[#1]{#2}}}


so that it appears to LaTeX as being centered about a zero-width box (I could make that a \textwidth box if I wanted). As long as the \includegraphics usage is centered on a line by itself, it will freely extend past the margins, as needed.

\documentclass{article}
\usepackage[demo]{graphicx}
\usepackage{lipsum}
\let\svincludegraphics\includegraphics
\renewcommand\includegraphics[2][]{\makebox[0pt]{\svincludegraphics[#1]{#2}}}
\begin{document}
\lipsum[3]
\begin{figure}[ht]
\centering
\includegraphics[width=1.1\textwidth,height=1cm]{file}
\caption{My caption}
\end{figure}
\lipsum[4]
\begin{figure}[ht]
\centering
\includegraphics[width=0.7\textwidth,height=1cm]{file}
\caption{My caption}
\end{figure}
\lipsum[4]
\end{document}


• +1 Your answer is shorter than mine and does basically the same. so I'll delete mine. Feb 26 '14 at 18:44
• Perfect answer! Thank you a lot! I am a basic TeX user and wouldn't work it out for hours. It saved me a plenty of time! :) Feb 27 '14 at 8:26
• @Marciszka You are most welcome. I edited my solution once I realized that I did not need the stackengine package for this solution (part of an earlier attempt). So you can remove that inclusion from your solution. [You'll find I use stackengine a lot, since I wrote it] Feb 27 '14 at 10:57