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.

I am creating a test question using exam.cls and I think it would be different if i will include image in the question. But i dont really know how should I insert it. i found a solution code that does exactly what I am expecting but these only compiles in 2012 version of TeXLive. Mine was 2009. Is there other posible solution for this to work in 2009 version? Or is there other possible package inspite of using adjustbox?

\documentclass{exam}
\usepackage{graphicx}
\usepackage[export]{adjustbox}

\newcommand*{\Image}[1]{\includegraphics[width=1.0cm,height=!,valign=m]{#1}}%
\begin{document}
You can insert image here as
\Image{../activity/ddd}
and your text can continue after it
and spill onto the next line as well, so you can see how this works.
\end{document}

Help

share|improve this question

1 Answer 1

up vote 4 down vote accepted

This will put the picture half above and half below the baseline:

\newcommand*{\Image}[1]{%
  \raisebox{-.5\height}{\includegraphics[width=1cm]{#1}}%
}

The macro uses only standard LaTeX constructions. Of course, graphicx must be loaded for \includegraphics (but it's a package included in all LaTeX distributions since the introduction of LaTeX2e).

If you want a default width for the image, but in some cases you want to modify it, then

\newcommand*{\Image}[2][1cm]{%
  \raisebox{-.5\height}{\includegraphics[width=#1]{#2}}%
}

will allow the syntaxes

\Image{../Activity/ddd}      % default width 1cm
\Image[2cm]{../Activity/ddd} % width 2cm

If you need to specify other keys to \includegraphics, it's better to pass the whole thing:

\newcommand*{\ImageF}[2][]{%
  \raisebox{-.5\height}{\includegraphics[#1]{#2}}%
}

so you can say

\ImageF[width=3cm,height=2in]{imagefile}

just as if \ImageF was \includegraphics.

share|improve this answer
    
\raisebox and \includegraphics are part of graphicx and no standard LaTeX constructions, aren’t they? –  Tobi Feb 15 '13 at 15:24
    
\raisebox is provided by the LaTeX kernel, not by graphicx; in general I consider standard LaTeX whatever is documented in Lamport's manual and \includegraphics is there. –  egreg Feb 15 '13 at 15:29
    
Exactly! :) Thanks. –  Kayla Feb 15 '13 at 15:49
    
@egreg: OK, thanks :-) “in general I consider standard LaTeX whatever is documented in Lamport's manual” ok for me – certainly graphicx is a standard package – but maybe not for absolute beginners ?! –  Tobi Feb 15 '13 at 16:13
    
Is it possible for the image be modified? Seeing the image will be 1cm width in default I think is fine but if image size can be modified which depends on the decided size of the image would be better. Is it possible? Example \Image{../Activity/ddd}[2cm]. –  Kayla Feb 15 '13 at 16:17

Your Answer

 
discard

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.