子图的垂直对齐 LATEX。

34
我正在撰写论文,遇到了一个问题,就是如何将两张图片并排放置,并使第二张图片在第一张图片垂直居中。我曾尝试使用subfigure代替subfloat,但都没有成功。
这是它的样子alt text http://img51.imageshack.us/img51/1174/screenshot20100224at712.png 我的代码如下:
\begin{figure}[H]
\centering  \subfloat[H][sparse($\mathbf{A}$)]{\includegraphics[width=0.28\textwidth]{sparsesmall} \label{sparse}}
    \subfloat[H][full($\mathbf{A}$)]{\includegraphics[width=0.55\textwidth]{fullsmall}\label{full}}
  \caption{Representation of $\mathbf{A}$ in MATLAB}
  \label{schematic}
\end{figure}

有什么建议可以让它看起来比现在更好吗?谢谢

4个回答

52

你也可以使用\raisebox{x}{\includegraphics[...]{...}},其中x为负数时将其向下移动,为正数时将其向上移动。


15
< p >< em >编辑:看起来< code >subfig包存在问题,特别是在与 hyperref 一起使用时。在这种情况下,请尝试如此答案中提到的subcaption包。

如果您使用subfig包,可以很容易地实现此操作。解决方案在手册的第5.4节中:

\newsavebox{\tempbox}
\begin{figure}[H]
\sbox{\tempbox}{\includegraphics[width=0.28\textwidth]{sparsesmall}}
\subfloat[sparse($\mathbf{A}$)]{\usebox{\tempbox}\label{sparse}}%
\qquad
\subfloat[full($\mathbf{A}$)]{\vbox to \ht\tempbox{%
  \vfil
  \includegraphics[width=0.55\textwidth]{fullsmall}
  \vfil}\label{full}}%
  \caption{Representation of $\mathbf{A}$ in MATLAB}\label{schematic}
\end{figure}

我没有测试过它,可能会有错别字,但应该能够工作。


由于某种原因,第二个图的标题对齐到了右侧。除此之外,一切都完美无缺,谢谢。 - Veronika D
2
FYI,subfig包现在已经过时了。因此,应该使用带有subcaption的答案(https://dev59.com/mnE95IYBdhLWcg3wY9D6#18795247)。 - Cyriac Antony

12

另一种解决方案(可以与subcaption包一起使用)是

\begin{figure}[p]
        \centering
        \begin{subfigure}{.49\linewidth}
            \centering
            \caption{Large Picture}
            \includegraphics{LARGEPIC}
        \end{subfigure}
        \hfill
        \begin{subfigure}{.49\linewidth}
            \centering
            \caption{SMALL PIC}
            \includegraphics{small picture}
            \begin{minipage}{.1cm}
            \vfill
            \end{minipage}
        \end{subfigure} 
        \caption{Two pictures}
\end{figure}

\vfill 单独使用无效,因此将其放入 minipage 中。


谢谢,我不能使用subfig包,所以这是我的选择(至少对我来说是这样)。 - stephanmg

3

我的方法是使用正方形的minipage,该minipage能够居中其内容:

\begin{figure}
\subfloat[Figure a]{%
\begin{minipage}[c][1\width]{0.5\textwidth}%
\includegraphics[clip,width=1\textwidth]{figurea}%
\end{minipage}}\subfloat[Figure b]{\centering{}%
\begin{minipage}[c][1\width]{0.5\textwidth}%
\begin{center}
\includegraphics[clip,width=0.6\textwidth]{figureb}
\par\end{center}%
\end{minipage}}
\caption{main caption}
\end{figure}

这段代码是由LyX生成的,所以看起来有些丑陋。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接