# Centering a pair of overfull PDFs

I'm trying to get to the bottom of how to position and center things.

Here I've placed two very large PDFs side-by-side. I scaled them down to the current size and tried to center them:

\documentclass{article}
\usepackage[margin=1in,showframe]{geometry}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{document}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\centering
\begin{figure}
%
\centering
\begin{minipage}[c][1\totalheight][t]{0.45\textwidth}%
\begin{center}
{\includegraphics[scale=0.085]{diagrams/pdf/square.pdf}}
\end{center}
\caption{I sit hard up against the left margin}
\end{minipage}\hfill{}%
%
\begin{minipage}[c][1\totalheight][t]{0.45\textwidth}%
\begin{center}
{\includegraphics[scale=0.085]{diagrams/pdf/square.pdf}}
\end{center}
\caption{I hang over the edge of the right margin}
\end{minipage}\hfill{}%
%
\end{figure}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\end{document}


It kind of works, but it only hangs over the right margin, so it's not truly centered. If I scale them down even further, there's a point where it's no longer a problem, but say it's impractical to make them any smaller than 0.085%, and you just want it to look more like this:

Notice how the page is perfectly symmetrical, with respect to the positions of the two figures and the excess is distributed evenly between the margins?

How can I achieve this? I thought my use of minipage would sort this out, but I guess not.

• Not a very good solution but you could get what you want by using the \hspace command. You can pass negative lengths to it. So if you are overlapping the right margin by let's say 2cm, you could put a \hspace{-1cm} before including the left image (or the minipage if you're using one). Let's hope there exists a better solution to this though... – Raven Aug 10 at 16:07
• @Raven Yes, thanks for mentioning it. I was going to but I forgot what the command was. I agree. It's difficult to know exactly how big the overlap is. With a bit of trial and error you can get pretty close, but if you have to do it several times, it gets frustrating fast. Also the captions become offset. – tjt263 Aug 10 at 16:19

Here is a way with the usage of this answer.

\documentclass{article}
\usepackage[margin=1in,showframe]{geometry}
\usepackage{graphicx}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{document}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\centering
\begin{figure}
%
\hspace{-0.025\textwidth}\makebox[1.05\textwidth][c]{
\noindent\begin{minipage}[t,outer sep=0]{0.45\textwidth}%
\begin{center}
{\includegraphics[width=\textwidth]{example-image-a}}
\end{center}
\caption{I sit hard up against the left margin}
\end{minipage}\hfill%
%
\begin{minipage}[t,outer sep=0]{0.45\textwidth}%
\begin{center}
{\includegraphics[width=\textwidth]{example-image-b}}
\end{center}
\caption{I hang over the edge of the right margin}
\end{minipage}}%
%
\end{figure}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\end{document}


output:

PS1: If \makebox command creates a box of 1.05\textwidth the 0.05\textwidth will be added after the text width ... So reduce it by half with \hspace{-0.025\textwidth}

PS2: use the appropriate width for the minipages, but take care of the outer sep in case you will use the whole width of the \makebox command.

Edit: Better way:

\documentclass{article}
\usepackage[margin=1in,showframe]{geometry}
\usepackage{graphicx}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{document}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\centering
\begin{figure}
%
\noindent\makebox[\textwidth][c]{
\noindent\begin{minipage}[t,outer sep=0]{0.525\textwidth}%
\begin{center}
{\includegraphics[width=\textwidth]{example-image-a}}
\end{center}
\caption{I sit hard up against the left margin}
\end{minipage}\hspace{0.5cm}%
%
\begin{minipage}[t,outer sep=0]{0.525\textwidth}%
\begin{center}
{\includegraphics[width=\textwidth]{example-image-b}}
\end{center}
\caption{I hang over the edge of the right margin}
\end{minipage}}%
%
\end{figure}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\end{document}

• Can makebox be used instead of minipage? Is it redundant in this case? Feels like we're playing with Russian nesting dolls. – tjt263 Aug 10 at 16:26
• \makebox is used here for the whole width to be used and this is the idea ... You could use any code that adds side by side the images ... I just used your way, but you can use any way available for side by side figures. – koleygr Aug 10 at 16:28
• Strange, I just tried your code and it didn't work for me the way you picture it. Actually it stays the same. – tjt263 Aug 10 at 16:32
• You did something wrong in the replacement of the figure/pdf dimensions. Or didn't copy-pasted everything needed ... You may edit your post with this failed example to find easier help. Try the second way too (it is better) – koleygr Aug 10 at 16:34
• I see, you have have replaced the scale with width. Was that intentional? That might have been it. Actually I only tried the second way I think. – tjt263 Aug 10 at 16:37