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 to create a command to can insert the image in a line of text question? Since I have a lot of question types made True/False, Short Answer types, Multiple choice, etc. I want the command to be compatible or can be usable in each of the question types. How should i make it? here is an example output to pdf for multiple choice:

multiple choice

I am currently using my created class based from the exam.cls help please.. thank you..

Code

\documentclass{exam}
\usepackage[{graphicx}
%\graphicspath{{/home/kayla/Desktop/activity/}}
%\DeclareGraphicsExtensions{.pdf,.jpg,.png}
\newcommand*{\Image}[1]{\includegraphics[width=1.0cm,height=1cm,valign=m]{#1}}%

\begin{document}
\begin{questions}
\question This look like a \Image{/home/kayla/Desktop/activity/ddd} but it    
 actually a \Image{/home/kayla/Desktop/activity/nest}
 dodmodod
\end{questions}
\end{document}

I made to place the image where my .tex file is placed. It always provides me an error. the

\newcommand*{\Image}[1]{\includegraphics[width=1.0cm,height=!,valign=m]{#1}}%

is highlighted and it says

illegal parameter number in definition of \reserved@a 
share|improve this question
    
The solution below should work just as well with other classes -- nothing class specific in there. –  Peter Grill Feb 15 '13 at 3:40
1  
To use the solution below you also need to add \usepackage[export]{adjustbox} to the preamble. –  Peter Grill Feb 15 '13 at 7:37

1 Answer 1

One way would be to use the adjustbox package to create a command the vertically aligns the image to middle of the line:

enter image description here

Code:

\documentclass{article}
\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{../images/EiffelWide}
and your text can continue after it
and spill onto the next line as well, so you can see how this works.
\end{document}
share|improve this answer
    
I am using exam.cls as the document class. I will use image in a question so it should be inside the \begin{question} & \end{question} tags. I tried the solution indicated above but it doesn't work. I am working in Ubuntu. –  Kayla Feb 15 '13 at 3:41
2  
Saying "it does not work" does not relaly provide any information from which to diagnose the problem. It would be best if you composed a fully compilable MWE including \documentclass and the appropriate packages that sets up the problem, and added it to you question. –  Peter Grill Feb 15 '13 at 3:43
    
Please create a complete MWE and add it to the question. –  Peter Grill Feb 15 '13 at 3:44
    
@Kayla: Perhaps your problem is that you are trying to go up the hierarchy. Try placing the image in the same place as the .tex file and see if that works. And, instead of describing the problem here in the comments, please see this link as to what a MWE is and add a MWE to the question. –  Peter Grill Feb 15 '13 at 4:40
1  
@Kayla: Well you could install the necessary packages and should work with 2009, but I do not have that version so can't test it. –  Peter Grill Feb 15 '13 at 19:36

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.