I am new to Latex and trying to center two figures using the following script:
\begin{figure}
\begin{center}
\subfloat{
\includegraphics[scale = 0.07,trim={40 5 25 10},clip]{Constantloadwithrigidboundary_Uy_X0Y0}}
\subfloat{
\includegraphics[scale = 0.07,trim={40 5 25 10},clip]{Constantloadwithrigidboundary_Vy_X0Y0}}
\end{center}
\end{figure}
As explained near the end of this video. Unfortunately in my case the figures do not center but rather are skewed to the right of the page as shown below:
I am also including the following:
\documentclass{article}
\usepackage[margin=1.2in]{geometry}
\usepackage{graphicx}
\usepackage{subfig}
At the beginning of my script. Why does this happen? How can I get my subfloats to center properly on the page?
Best Answer
The problem is one of overflowing the allocated text width, as shown in the first figure set in the MWE below (where the
showframe
option of thegeometry
package shows explicitly the text area allocated by the current document settings). TeX honors the left margin, but if the figure-set is too large, it spills out the right.There are three fixes:
You can reduce the width of the figure-set to fit inside the margins allocated; this is the route taken in the 2nd figure-set on the 1st page.
You can trick LaTeX into momentarily ignoring the margins, as I do on page 2 of the MWE. With
\makebox[0pt]{\begin{minipage}{1.2\textwidth}...\end{minipage}}
, I create aminipage
large enough to handle the oversized figure-set, but then place it in a zero-width\makebox
subject tocenter
ing. The\makebox
thus makes TeX unaware that theminipage
exceeds the margin bounds. Note that I also use an\hfill
to employ the full width of theminipage
, lest theminipage
be centered, but not its content. Or, finally,You can set a
\newgeometry
expanding the margins, possibly for a single page only (shown on pages 3,4 in MWE below).The MWE.