39

I am inserting two graphs (of different size) in the following way:

\begin{figure}[H]
\begin{center}
\includegraphics[scale=0.5]{graph1.eps}
\includegraphics[scale=0.3]{graph2.eps}
\caption{\label{fig:scaled_diss}}
\end{center}
\end{figure}

which would be perfect if the graphs were of near-identical build, but it's currently resulting in the graph borders being mis-aligned, as in:

enter image description here

So the right graph doesn't have tics on the x axis. How do I make it that the graphs are aligned at the top, then the scaling can be altered, to give something like this:

enter image description here

  • 1
    don't use scale= use height= so they both scale to the same height. (and don't use H :-) – David Carlisle Mar 10 '13 at 21:41
  • 1
    @David But using "height=" won't give the desired result -- in the desired result, the two images do not have the same height, because of the x-axis labels in the first image. (And for examples like the way the figures and text are used together seamlessly in the question itself, H is a reasonable way to ensure the result isn't nonsense, if you need to use the figure command at all. :-) – Matt Jan 18 '14 at 10:55
50

Use the adjustbox package's valign=t key to align the graphics contents at the top:

enter image description here

\documentclass{article}
\usepackage[export]{adjustbox}% http://ctan.org/pkg/adjustbox
\begin{document}
\begin{figure}
  \centering
  \includegraphics[scale=0.5,valign=t]{example-image-a}
  \includegraphics[scale=0.3,valign=t]{example-image-b}
  \caption{A caption\label{fig:scaled_diss}}
\end{figure}
\end{document}

Using the export key with adjustbox, this will load the graphicx package, and allow you to use its keys as part of \includegraphics.

Also, for your specific example, it may be more advisable to use a fixed height, rather than a scale. This way you can more readily provide the same vertical alignment of your items (graphics or otherwise).

  • I got this error: Option clash for package adjustbox.. Now I have to check with all other packages... :-( – pushpen.paul Sep 2 '17 at 14:47
12

Since adjustbox is not easy to install on ubuntu-12.04 the solution proposed in Aligning image and text on top, with minipages can be useful.

\begin{tabular}{p{0.5\textwidth} p{0.5\textwidth}}
  \vspace{0pt} \includegraphics[width=0.49\textwidth]{example-image-a} &
  \vspace{0pt} \includegraphics[width=0.49\textwidth]{example-image-b}
\end{tabular}
8

A third alternative is the stackengine package, with its \belowbaseline command, which places the top of an object a given distance below the baseline, shown below without, then with \belowbaseline.

\documentclass{article}
\usepackage{stackengine}
\usepackage{graphicx}
\begin{document}

\def\figa{\rule{1in}{1in}}
\def\figb{\scalebox{.6}{\figa}}

\begin{figure}[H]
\begin{center}
\figa~\figb
\caption{\label{fig:scaled_diss}}
\end{center}
\end{figure}

\begin{figure}[H]
\begin{center}
\belowbaseline[0pt]{\figa}~\belowbaseline[0pt]{\figb}
\caption{\label{fig:scaled_diss}}
\end{center}
\end{figure}

\end{document}

enter image description here

3

And yet another alternative is to use the graphboxpackage. It has some extra options for \includegraphics. The top vertical aligment would be achived using align=t option:

\documentclass{article}
\usepackage{graphbox,graphicx}

\begin{document}

\begin{figure}
\centering
\includegraphics[align=t,scale=0.5]{example-image}
\includegraphics[align=t,scale=0.3]{example-image}
\caption{Caption text\label{fig:scaled_diss}}
\end{figure}

\end{document}

I'd strongly advise against the use of the float package H option. Furthermore using \centering rather than the environment center produces less vertical space.

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.