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.

How can I vertically center two images next to one another? Here is some example code:


I want the center line of both images to be at the same height.

share|improve this question
possible duplicate: This Question –  Yossi Farjoun Dec 16 '10 at 14:35

6 Answers 6

up vote 46 down vote accepted

The baseline of images is at their bottom. You could change that by using \raisebox. For example:


Gives vertically centered images, here black rectangles because of the demo option:

alt text

Raising their baseline by .5\height has the nice effect that also following text would be aligned at the new baseline at the vertical center.

Alternatively, you could use \vcenter, which is working fine as well:

  following text

Note: \vcenter requires mathmode. \hbox for the argument may be necessary too.

share|improve this answer
@stephan: is \height defined to be the height of the box? –  Yossi Farjoun Dec 16 '10 at 14:39
@Yossi: Yes, it's the height of the box in the argument. Besides \height, we could also use \totalheight (in the case if there would be a depth). –  Stefan Kottwitz Dec 16 '10 at 14:47
@stephan: Thanks, that's a much better answer than mine in the question I link to in the comment above...perhaps you could add yours to that question as well? or at-least post a link. –  Yossi Farjoun Dec 16 '10 at 14:50
Wow, that's perfect. Thank you! –  Chris Cannon Dec 16 '10 at 14:53
@Pieter What should I say, without details such as the error message and your code. Perhaps post a new and precise question on the site. –  Stefan Kottwitz Jun 10 '12 at 16:21

Just use \parboxes. Let's say we want two include the two jpg files: first picture and second picture The following code does it:


%% first attempt (but needs modifications in case of optional parameters to \includegraphics)


%% better: (general command to vertically center horizontal material)


How can I vertically center two images next to one another? I want the center
line of both images to be at the same height.

\vcenteredhbox{\includegraphics{figure1.jpg}} and
\vcenteredhbox{\includegraphics{figure2.jpg}} and \vcenteredhbox{\LARGE This too
is vertically centered}


The result of the pdflatex compilation is: outcome of pdftex run

share|improve this answer
Could you explain how your \vcenteredinclude works? –  doncherry May 1 '11 at 16:59
@doncherry: Well, the LaTeX \parbox macro by default centers its content respective to the surrounding baseline. But it has a mandatory argument to specify its width. Contrarily to other LaTeX macros such as \makebox or \raisebox there is no automatic setting of a macro \width to refer to the width of the enclosed material (indeed, there is no such natural width as it is destined to be specified by the user). So I just use the most basic TeX primitives dealing with boxes to get this width and pass it to \parbox as its first mandatory argument. –  jfbu May 2 '11 at 7:12
I have edited my code to add a better, general purpose command, \vcenteredhbox which uses \parbox to typeset horizontal material in a vertically centered manner relative to the surrounding baseline. –  jfbu May 2 '11 at 10:43
\vcenter is a primitive and faster than \parbox. –  Ahmed Musa Dec 6 '11 at 15:41

I find ConTeXt's syntax for image combinations to be much cleaner. I wish some LaTeX package provided a similar interface.

\useMPlibrary[dum] % for dummy images

which gives

enter image description here

You can change location=middle to location=high or location=low to get top and bottom aligned images.

share|improve this answer
% Declare a dedicated box, because temporary boxes may be busy:
% Declare unique keys for the command \vcenterprocess. We could have done
% this using a key command or key environment, or even pathkeys.
  % Set the alignment of the graphics or text:
% #1=keys, #2=attributes. The presence of 'fig=' in #2 means
% that we have a graphics; 'text=' implies that this is a plain
% text.
    % PDF can handle many image formats:
    % We can do some calculations inside the box.
    % Loop over all the submitted items. If #2 is a macro,
    % then the attributes have been put in a macro
    % by the user, in which case we need to expand the macro
    % at least one step.
      % Split the attributes, so that we know whether a file
      % or plain text has been given; and to get filename, viewport, etc.
      % The inputpath normally contains outer braces. The image or text
      % attributes too might have outer braces. Remove outer braces here.
        % The keys and attributes might contain active commas, active equality
        % sign (babel), etc. They may also contain double commas, equals, and
        % spurious spaces. So normalize the key-val list here.
            % Splitting might have introduced double, leading or trailing commas, and
            % spurious spaces. So normalize the csv list here.
          \xwm@err{No filename in second argument of
      % Set the graphics input path. We can hack directly into graphics package's 
      % input path mechanism here because we're in a local group.

% CTAN's xwatermark needs updating:
% Example (create your own document and garbage text).
% \garbagetext is a private garbage generator.
  fig   ={file=comet1, viewport=20 21 590 400, scale=.1},
  fig   ={file=comet1, viewport=20 21 590 400, scale=.08},
  text  ={This too is vertically centered}
%  fileext=jpeg,

enter image description here

share|improve this answer
I reduced the size of the image. I hope you didn't mind. –  percusse Dec 9 '11 at 4:51
I don't know how to do it here. Please teach me. –  Ahmed Musa Dec 9 '11 at 5:28
Actually I downloaded the image, cropped it and re-uploaded. So, not much to teach :) –  percusse Dec 9 '11 at 5:33
@percusse, Ahmed Musa: A couple of different ways to crop images / PDFs were discussed at meta.tex.stackexchange.com/questions/1799/… –  Jake Dec 9 '11 at 5:40
@AhmedMusa This is an excellent answer, but maybe a bit rather complicated for the average user of this site. Won't you please add a bit of explanation either in the code or the answer itself and there is no reason why you shouldn't trump up ltxkeys a bit, its an excellent package. –  Yiannis Lazarides Dec 9 '11 at 10:00

Embed the figure into a tabular cell which is vertically aligned inline (in contrast to a figure).


line before\\
line before\\
text before
text between
text after\\
line after\\
line after


@{} removes the column padding.

share|improve this answer
This works great and it's quite concise. I used your solution to define a convenient command: \newcommand{\vmiddle}[1]{\begin{tabular}{@{}c@{}} {#1} \end{tabular}}. Thanks for posting. –  user148885 Aug 17 at 11:40

Use trimming of one figure in a negative way (negative value for 'trim').

An easy, but dirty way to achieve a more vertical alignment is by 'negatively' trimming your figure. This has the advantage that your subcaptions ((a) and (b)), when using the subfigure package, remain aligned and do not vertically move with the alignment of the figures.

\subfigure[subcaption (a)]{\includegraphics[width = 0.4\linewidth]{image_a.jpg}} \hspace{3ex}  
\subfigure[subcaption (b)]{\includegraphics[width = 0.4\linewidth, trim = 0cm -2cm 0cm 0cm]{image_b.jpg}}  
\caption{caption text here.}  

The negative value for the 'bottom'-input for 'trim' causes the second figure to move upward by 2cm (in this case).

share|improve this answer

Your Answer


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.