The following code is producing an error:
\begin{figure}[htbp!]
\subfloat{
\begin{minipage}[c][Structured Mesh]{0.5\textwidth}
\centering
\includegraphics[scale=0.4]{ch-SmallStrain/Graphics/Structured}
\end{minipage}}
\subfloat{
\begin{minipage}[c][Unstructured Mesh]{0.5\textwidth}
\centering
\includegraphics[scale=0.4]{ch-SmallStrain/Graphics/Unstructured}
\end{minipage}}
\\
\subfloat{
\begin{minipage}[c][Structured Mesh, zoomed to red box shown above]{0.5\textwidth}
\centering
\includegraphics[scale=0.2]{ch-SmallStrain/Graphics/StructuredCloseup}
\end{minipage}}
\subfloat{
\begin{minipage}[c][Unstructured Mesh, zoomed to red box shown above]{0.5\textwidth}
\centering
\includegraphics[scale=0.2]{ch-SmallStrain/Graphics/UnstructuredCloseup}
\end{minipage}}
\caption{Meshes for the Shearing example\label{fig:Meshes-for-the}}
\end{figure}
The error is:
! Missing number, treated as zero.
S
l.634 \end{minipage}}
which occurs at each \end{minipage}
. This seems to me like the width arguments {0.5\textwidth}
are not being recognized, and indeed the error goes away if I remove the optional arguments in the []
. Is there a way to fix this error while keeping the optional arguments?
Edit:
I forgot to mention that I am using the subfig package and the second optional argument is supposed to be the caption of the subfigure.
Best Answer
I assume you intend the second argument in brackets following
\begin{minipage}
to act as the subfloat's caption. If that's your objective, you should place the argument immediately after\subfloat
rather than after\begin{minipage}
.Note that the
minipage
environment can take up to three optional arguments -- an "outer" vertical alignment indicator, which can bet
fortop
,c
forcenter
, andb
for bottom; a height variable (a TeX "length" entity); and an "inner" position indicator -- and two mandatory arguments: a length variable to set the intended width of the environment and the actual contents of the minipage, both to be placed in curly braces.Another observation: Unless there's a very good reason for making the subfloat graphs have different widths, you may just want to give all four the same width. This may be achieved by setting the option
width=\linewidth
when executing\includegraphics
.