Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I'm trying to compare two diagrams in pdf format side by side. I have this post - Two figures side by side to get some hint.

This is the code that I'm coming up with.

\begin{figure}
\begin{minipage}[t]{0.45\linewidth}
\includegraphics[scale=0.30]{before.pdf}
\caption{(a) Before}
\end{minipage}%

\hfill\vrule\hfill
\begin{minipage}[t]{0.45\linewidth}
\includegraphics[scale=0.3]{after.pdf}
\caption{(b) After}
\end{minipage}%
\caption{Hello}
\end{figure}

And this is the result, which is not exactly what I expected.

enter image description here

  • What modifications are needed to make the pictures sit side by side?
  • I just want the caption (a) Before and (b) After without any Figure prepended. What should I do?
share|improve this question
4  
Avoid the empty line before \hfill\vrule\hfill; also declare \centering after \begin{figure} –  egreg Nov 14 '12 at 18:30
2  
And maybe use width=\linewidth instead of scale=0.30 in your \includegraphicssince otherwise the width of the image may exceed the width of the minipage. –  Vincent Nivoliers Nov 14 '12 at 18:32
add comment

2 Answers

up vote 4 down vote accepted

Although you can solve perfectly the problem with minipages, for sub-figures with captions enumerated with letters (a,b,..) you can use also the package subcaption to simplify a little your code, as you do not need write "(a)" and "(b)", but mainly because the flexibility that you have with this package, as listing the subfigures. Note that neither is it necessary in the MWE the use of \centering nor include file extension (.pdf).

Note: Remove the demo option in graphicx package to use your diagrams instead of the black boxes:

\documentclass{article}
\usepackage[demo]{graphicx} % remove option for real images
\usepackage[list=true]{subcaption}

\begin{document}
\listoffigures    
\vspace{3cm}

\begin{figure}[h]%

\begin{subfigure}[h]{0.4\textwidth}
\includegraphics[width=\textwidth]{before}
\caption{Before}
\end{subfigure}
\hfill\vrule\hfill
\begin{subfigure}[h]{0.4\textwidth}
\includegraphics[width=\textwidth]{after}
\caption{After}
\end{subfigure}%

\caption[Hello]{Hello, this a minimal working example}
\end{figure}
\end{document}

enter image description here

Alternatively you can use also subfig or subfigure packages for the same reasons. See Setting default distance between subfigures for examples with these packages.

share|improve this answer
    
Compilation of your LaTeX example on my mac gives me this error message: ERROR: Package subcaption Error: 'caption' package not loaded –  prosseek Nov 14 '12 at 22:09
    
@prosseek, have you caption.sty in your mac? Try with \usepackage{caption} before of \usepackage{subcaption}. At least in TeXLive2012 this is not needed, as subcaption load also caption.sty and caption3.sty, but who know ... –  Fran Nov 14 '12 at 23:00
    
\usepackage{caption} solved the issue. Thanks! –  prosseek Nov 15 '12 at 0:13
add comment

Thanks to egreg and Vincent, I could make the correction. The problem was the empty line that caused the wrong alignment, and I replaced caption with centering to remove the Figure

enter image description here

\begin{figure}
\begin{minipage}[t]{0.49\linewidth}
\centering
\includegraphics[width=\linewidth]{before.pdf}

(a) Before
\end{minipage}%
\hfill\vrule\hfill
\begin{minipage}[t]{0.49\linewidth}
\centering
\includegraphics[width=\linewidth]{after.pdf}

(b) After
\end{minipage}
\caption{Hello}
\end{figure}

share|improve this answer
1  
One \centering for minipage is sufficient: it is not a command taking arguments, but a declaration. –  egreg Nov 14 '12 at 22:32
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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