TransWikia.com

Make two figures aligned at top

TeX - LaTeX Asked by dplanet on September 27, 2021

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

5 Answers

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 captionlabel{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).

Correct answer by Werner on September 27, 2021

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.5textwidth} p{0.5textwidth}}
  vspace{0pt} includegraphics[width=0.49textwidth]{example-image-a} &
  vspace{0pt} includegraphics[width=0.49textwidth]{example-image-b}
end{tabular}

Answered by zeliboba on September 27, 2021

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}

deffiga{rule{1in}{1in}}
deffigb{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

Answered by Steven B. Segletes on September 27, 2021

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 textlabel{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.

Answered by Guilherme Zanotelli on September 27, 2021

perhaps an even simpler one, using multicol:

begin{figure}
begin{center}
begin{multicols}{2}
includegraphics[width=0.65textwidth]{whatever.eps}
includegraphics[width=0.34textwidth]{whatever.eps}
end{multicols}
end{center}
end{figure}

Answered by Manuel Lera Ramírez on September 27, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP