3

I tried following this answer to get my subfigures to fit ignoring margins, but as soon as I add the \makebox call, several errors are returned relating to what look like commands internal to packages at the very least, if not LaTeX internal commands. A simplified case to reproduce this issue is below.

This happens using both pdfLaTeX and LuaLaTeX on Overleaf v2.

To reproduce the errors with the following example:

Uncomment the \makebox line and the closing brace under the last \end{figure}

Errors:

! You can't use `\hrule' here except with leaders.
\caption@hrule ->\hrule 
                        \@height \z@ 
l.36 }

To put a horizontal rule in an hbox or an alignment,
you should use \leaders or \hrulefill (see The TeXbook).

! Missing number, treated as zero.
<to be read again> 
                   \vskip 
l.36 }

A number should have been here; I inserted `0'.
(If you can't figure out why I needed to see a number,
look up `weird error' in the index to The TeXbook.)

! Illegal unit of measure (pt inserted).
<to be read again> 
                   \vskip 
l.36 }

Dimensions can be in units of em, ex, in, pt, pc,
cm, mm, dd, cc, nd, nc, bp, or sp; but yours is a new one!
I'll assume that you meant to say pt, for printer's points.
To recover gracefully from this error, it's best to
delete the erroneous units; e.g., type `2' to delete
two letters. (See Chapter 27 of The TeXbook.)

! Missing \endgroup inserted.
<inserted text> 
                \endgroup 
l.36 }

I've inserted something that you may have forgotten.
(See the <inserted text> above.)
With luck, this will get me unwedged. But if you
really didn't forget anything, try typing `2' now; then
my insertion and my current dilemma will both disappear.

! Missing } inserted.
<inserted text> 
                }
l.36 }

I've inserted something that you may have forgotten.
(See the <inserted text> above.)
With luck, this will get me unwedged. But if you
really didn't forget anything, try typing `2' now; then
my insertion and my current dilemma will both disappear.

! Too many }'s.
\@endfloatbox ...pagefalse \outer@nobreak \egroup 
                                                  \color@endbox 
l.37 \end{figure}

You've closed more groups than you opened.
Such booboos are generally harmless, so keep going.


! LaTeX Error: \begin{document} ended by \end{figure}.

See the LaTeX manual or LaTeX Companion for explanation.
Type  H <return>  for immediate help.
 ...                                              

l.37 \end{figure}

Your command was ignored.
Type  I <command> <return>  to replace it with another command,
or  <return>  to continue without it.

! Extra \endgroup.
<recently read> \endgroup 

l.37 \end{figure}

Things are pretty mixed up, but I think the worst is over.

Code:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[demo]{graphicx}
\usepackage{subcaption}
\usepackage[version=4]{mhchem}

\begin{document}

\begin{figure}[!htb]
%\makebox[\linewidth][c]{%
\begin{subfigure}[t]{0.4\textwidth}
\centering
\includegraphics[width=\textwidth]{photos/IMG_20180615_144758.jpg}
\caption{pic 1}
\end{subfigure}%
~
\begin{subfigure}[t]{0.4\textwidth}
\centering
\includegraphics[width=\textwidth]{photos/IMG_20180615_144616.jpg}
\caption{pic 2} 
\end{subfigure}%
~
\begin{subfigure}[t]{0.4\textwidth}
\centering
\includegraphics[width=\textwidth]{photos/IMG_20180615_145752.jpg}
\caption{pic 3} 
\end{subfigure}%
~
\begin{subfigure}[t]{0.4\textwidth}
\centering
\includegraphics[width=\textwidth]{photos/IMG_20180615_153117.jpg}
\caption{pic 4}
\end{subfigure}%
\caption{Photos of the process}
\label{photos}
%}
\end{figure}

\end{document}
3

Welcome to TeX.SE! You only need to put the closing brace before \caption.

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[demo]{graphicx}
\usepackage{subcaption}
\usepackage[version=4]{mhchem}

\begin{document}

\begin{figure}[!htb]
\makebox[\linewidth][c]{%
\begin{subfigure}[t]{0.4\textwidth}
\centering
\includegraphics[width=\textwidth]{photos/IMG_20180615_144758.jpg}
\caption{pic 1}
\end{subfigure}%
~
\begin{subfigure}[t]{0.4\textwidth}
\centering
\includegraphics[width=\textwidth]{photos/IMG_20180615_144616.jpg}
\caption{pic 2} 
\end{subfigure}%
~
\begin{subfigure}[t]{0.4\textwidth}
\centering
\includegraphics[width=\textwidth]{photos/IMG_20180615_145752.jpg}
\caption{pic 3} 
\end{subfigure}%
~
\begin{subfigure}[t]{0.4\textwidth}
\centering
\includegraphics[width=\textwidth]{photos/IMG_20180615_153117.jpg}
\caption{pic 4}
\end{subfigure}%
}

\caption{Photos of the process}
\label{photos}
\end{figure}

\end{document}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.