我试图让两个子图具有相同的高度并为此定义了长度,但它们之间的长度被设置为零。我的理解是,这与子图环境有关。有什么办法可以实现这一点吗?
小版本的图片,供参考
\documentclass{article}
\usepackage{graphicx}
\usepackage{subcaption}
\begin{document}
\begin{figure}
\centering
\begin{subfigure}[b]{0.45\linewidth}
\newlength\mycustomlen
\setlength\mycustomlen{50pt}
\includegraphics[height=\mycustomlen]{smiley.png}
\caption{height is mycustomlen: \the\mycustomlen}
\end{subfigure}
\hfill
\begin{subfigure}[b]{0.45\linewidth}
\includegraphics[height=\mycustomlen]{smiley.png}
\caption{this picture doesnt show up\\
mycustomlen: \the\mycustomlen}
\end{subfigure}
\end{figure}
\end{document}
答案1
只需将长度放在子图之外:
\documentclass{article}
\usepackage{graphicx}
\usepackage{subcaption}
\newlength\mycustomlen
\begin{document}
\begin{figure}
\centering
\setlength\mycustomlen{50pt}
\begin{subfigure}[b]{0.45\linewidth}
\includegraphics[height=\mycustomlen]{smiley.png}
\caption{height is mycustomlen: \the\mycustomlen}
\end{subfigure}
\hfill
\begin{subfigure}[b]{0.45\linewidth}
\includegraphics[height=\mycustomlen]{smiley.png}
\caption{this picture doesnt show up\\
mycustomlen: \the\mycustomlen}
\end{subfigure}
\end{figure}
\end{document}
答案2
如果我正确理解了你的问题,那么对于等高图像你不需要定义特殊的长度,而只需使用\setkeys{Gin}{height=<desired height of images>}
:
\documentclass{article}
\usepackage{graphicx}
\usepackage{subcaption}
\begin{document}
\begin{figure}
\setkeys{Gin}{height=50pt}
\begin{subfigure}[t]{0.45\linewidth}
\includegraphics{example-image-duck} %{smiley.png}
\caption{height is mycustomlen: \the\mycustomlen}
\end{subfigure}
\hfill
\begin{subfigure}[t]{0.45\linewidth}
\includegraphics{example-image-duck} %{smiley.png}
\caption{this picture doesn't show up\\
mycustomlen: \the\mycustomlen}
\end{subfigure}
\end{figure}
\end{document}
(因为我没有笑脸图,所以我用标准示例图