2

I am using the following code

\documentclass{article}
\usepackage{graphicx} 
\usepackage{subfig}

\begin{document}    
\begin{figure}[t]%
        \centering
        \subfloat[Image 1\label{fig:img1}]{{\includegraphics[scale=0.05]{img1.png} }}%
        \subfloat[Image 2\label{fig:img2}]{{\includegraphics[scale=0.05]{img2.png} }}%
        \caption{Two images}%
        \label{fig:imgs}%
    \end{figure}
\end{document}

However img1 and img2 have different heights but same width. How do I display them at vertically alligned position? Basically the center of both the images should be at the same horizontal line.

  • And where should be images caption? It would be helpful, if you will extend your code snippet to complete small document. Welcome to Tex.SE! i – Zarko Jul 7 '17 at 7:54
  • Captions should be aligned together, only the images should be centered – canonball Jul 7 '17 at 8:02
  • Please always add a minimal but working example (MWE) instead of only a code snippet. Currently we, e.g., can only speculate which package you are using to have \subfloat. – Schweinebacke Jul 7 '17 at 8:37
2

Like this?

enter image description here

One of among possible solutions for above figure is enclose smaller image in tikz node with minimum height equal to height of taller image. This means, that you need first to measure its height and than accordingly set TikZ node size:

\documentclass{article}
\usepackage[demo]{graphicx} 
\usepackage{subfig}

\usepackage{tikz}
\newlength\imageheight% for determining height of taller image

\begin{document}
    \begin{figure}[ht]%
% measurement of height of the taller image
\settoheight{\imageheight}{\includegraphics[height=3cm]{img1.png}}
    \centering
% since I haven't your image,
% I simulate their different heights with prescribed "height"
\subfloat[Image 1\label{fig:img1}]{\includegraphics[height=3cm]{img1.png}}%
\hfil
\subfloat[Image 2\label{fig:img2}]{\tikz\node[minimum height=\imageheight]{\includegraphics[height=2cm]{img2.png}}; }%
    \caption{Two images}%
\label{fig:imgs}%
    \end{figure}
\end{document}
  • what does ht in \begin{figure}[ht] do? – canonball Jul 7 '17 at 8:35
  • ht are options for figure placement: here (where is inserted in text), if there is enough space, otherwise on the top of the next page. Tank you for completing of your code snippet. Now I complete my answer and also add some more explanation, See, if it is helpful to you. – Zarko Jul 7 '17 at 15:04
1

You could use a minipage grid:

\documentclass{article}

\usepackage{subcaption}
\usepackage{mwe}

\begin{document}

\begin{figure}
    \centering
    \begin{minipage}[c]{.5\textwidth}
      \centering
      \includegraphics[scale=0.5]{example-image-a}
    \end{minipage}%
    \begin{minipage}[c]{.5\textwidth}
      \centering
      \includegraphics[scale=0.25]{example-image-b} \\
    \end{minipage}
    \begin{minipage}{.5\textwidth}
      \subcaption{Image 1}\label{fig:img1}
    \end{minipage}%
    \begin{minipage}{.5\textwidth}
      \subcaption{Image 2\label{fig:img2}}%
    \end{minipage}
    \caption{Two images}%
    \label{fig:imgs}%
\end{figure}

\end{document}

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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