6

MWE:

\documentclass{scrbook}

\usepackage[showframe]{geometry}
\usepackage[draft]{graphicx}
\usepackage{blindtext}
\usepackage{subcaption}

\begin{document}

\begin{figure}
\begin{subfigure}{.5\textwidth}
    \centering
    \includegraphics[height=175px, width=200px]{dummy.png}
    \caption{left}
\end{subfigure}%
\begin{subfigure}{.5\textwidth}
    \centering
    \includegraphics[height=175px, width=150px]{dummy.png}
    \caption{right}
\end{subfigure}
\caption{\blindtext}
\end{figure}

\end{document}

and a picture:

a busy cat

How can I arrange the subfigures so that the space between the right fig and the right border equals the space between the left fig and the left border? I marked the space with red lines.

Any help is appreciated.

2 Answers 2

5

Use \subcaptionbox, so you don't have to guess.

In the example I added the width, but probably your code will just set the height. Don't use px units, because the size of 1px is not predetermined.

Instead of \hfil between the images you can use \hspace{<length>} (don't forget a % if it comes last in a line).

\documentclass{scrbook}

\usepackage[showframe]{geometry}
\usepackage{graphicx}
\usepackage{blindtext}
\usepackage{subcaption}

\begin{document}

\begin{figure}
\centering

\subcaptionbox{left\label{sub-left}}{%
  \includegraphics[height=175bp,width=.6\textwidth]{example-image}%
}\hfil
\subcaptionbox{right\label{sub-right}}{%
  \includegraphics[height=175bp,width=.2\textwidth]{example-image}%
}

\caption{\blindtext}
\end{figure}

\end{document}

enter image description here

0
5

You can set the widths of the two subfigure environments directly to 200px and 150px, respectively. Next, set the widths of both graphs to \linewidth. Finally, insert \hspace*{\fill} to the left of the left-hand subfigure, between the subfigures, and to the right of the right-hand subfigure.

If you want a fixed amount of space between the subfigures of, say, 1 cm instead of \fill, simply replace the middle \hspace*{\fill} instruction with \hspace{1cm}.

enter image description here

\documentclass{scrbook}

\usepackage[showframe]{geometry}
\usepackage[draft]{graphicx}
\usepackage{subcaption}

\begin{document}

\begin{figure}

\hspace*{\fill}
\begin{subfigure}{200bp}
    \includegraphics[height=175bp, width=\linewidth]{dummy.png}
    \caption{left}
\end{subfigure}%
\hspace*{\fill}
\begin{subfigure}{150bp}
    \includegraphics[height=175bp, width=\linewidth]{dummy.png}
    \caption{right}
\end{subfigure}
\hspace*{\fill}

\caption{Two subfigures placed side by side}
\end{figure}

\end{document}
5
  • Unit px? That's really wrong! Yes, it's used by the OP, but we should know better. The unit px can be used in pdftex, but its value is not fixed (default is 1bp, but one can't count on it).
    – egreg
    Commented Mar 13, 2015 at 21:35
  • @egreg - I've updated the code and replaced px with bp -- just to play it safe. :-)
    – Mico
    Commented Mar 13, 2015 at 21:57
  • @Mico - Thank you :) It works, but I will be using the other answer, as that one works even without specifying the width.
    – mstrkrft
    Commented Mar 14, 2015 at 0:22
  • @mstrkrft - You are of course free to choose any answer you prefer. Do be aware, though, that the other answer very much specifies two widths as well -- 0.6\textwidth and 0.2\textwidth, respectively. The ratio of these two widths is 3:1, which is quite different from what you gave in your original example, viz., 4:3.
    – Mico
    Commented Mar 15, 2015 at 17:22
  • @Mico - I know. But the code above works even without specifying the widths, which is nice :)
    – mstrkrft
    Commented Mar 18, 2015 at 18:39

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .