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.

So I repeatedly use this format for embedding a picture and some text beside it,

\begin{tabular}{l l}
\begin{minipage}{0.3\textwidth}
\includegraphics[SCALE]{NAME}
\end{minipage}
&
\begin{minipage}{0.7\textwidth}
TEXT
\end{minipage}
\end{tabular}

I want to create a new command that will take arguments for scale, the picture name, and the text I want to have beside it. How would I create this command? Can I use the \newcommand or do I have to use \newenvironment?

e.g. \wrappic{0.6}{flower.jpg}{this is a rose!}

share|improve this question
add comment

1 Answer

up vote 8 down vote accepted

Of course you can!

\newcommand{\wrappic}[3][1]{%
  \par\noindent\mbox{%
  \begin{minipage}{0.3\textwidth}
  \includegraphics[scale=#1]{#2}
  \end{minipage}%
  \begin{minipage}{0.7\textwidth}
  #3
  \end{minipage}}
  \par}

Note that the tabular environment serves no purpose and it also creates an overfull box, because you're not taking into account the intercolumn spaces, so that the sum would be larger than the text width.

Now \wrappic[0.6]{flower.jpg}{this is a rose!} will do what you want. If you type \wrappic{flower.jpg}{this is a rose!} no scaling is applied.

In general, using scale= is discouraged, as it depends on the size of the picture and you'd need to adjust it manually. I'd propose something different:

\newcommand{\wrappicauto}[3][\dimexpr\textwidth-1em\relax]{%
  \par\noindent\mbox{%
  \begin{minipage}{0.3\textwidth}
  \includegraphics[width=#1]{#2}
  \end{minipage}%
  \begin{minipage}{0.7\textwidth}
  #3
  \end{minipage}}
  \par}

so that

\wrappicauto{flower.jpg}{this is a rose!}

will scale automatically the picture to occupy 3/10 of the text width minus a small separation space.

If you need a different width, then you can say

\wrappicauto[3cm]{flower.jpg}{this is a rose!}
share|improve this answer
    
Cool, this is good, is there a way to make scale an optional argument? Since some pictures are rather tall and skinny, so they will scale very awkwardly to fill even just 3/10 of the page –  Dan Nov 11 '12 at 22:25
    
How would I go about making the picture bigger using a higher scale argument? If I want it to be bigger, I find that the text then overlaps the picture, can I get it so that the text fills whatever portion of the width of the page is left from the picture + tiny gap to the right margin? –  Dan Mar 10 '13 at 2:26
    
@Dan You have to recompute the horizontal space reserved to the figure and the text, currently 30% and 70%. –  egreg Mar 10 '13 at 10:12
add comment

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.