我尝试过这个答案使我的子图忽略边距以适应,但一旦我添加调用\makebox
,就会返回几个错误,这些错误至少与看起来像包内部的命令有关,如果不是 LaTeX 内部命令的话。下面是一个重现此问题的简化案例。
在 Overleaf v2 上使用 pdfLaTeX 和 LuaLaTeX 时都会发生这种情况。
使用以下示例重现错误:
取消注释该\makebox
行以及最后\end{figure}
错误:
! 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.
代码:
\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}
答案1
欢迎使用 TeX.SE!您只需将右括号前 \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}