Tell me more ×
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.

Possible Duplicate:
How to superimpose LaTeX on a picture?

Take this image for example:

enter image description here

How can I add labels to an image as done above without manually drawing a line and adding text at the end of the line?

share|improve this question
Please have a look at the package overpic. – Marco Daniel Jan 8 '12 at 14:44
1  
You should not miss one of the star questions of TeX.SX. – percusse Jan 8 '12 at 15:59
@Marco: tug.org/PSTricks/main.cgi?file=Examples/overlay#overpic The example with the tiger is the result I want, but I still have to manually draw the lines. Do you have something more specific I can look up than just overpic? – howardh Jan 8 '12 at 16:07
@howardh: What do you mean with have to manually draw the lines? – Marco Daniel Jan 8 '12 at 16:12
show 1 more comment

marked as duplicate by Yiannis Lazarides, Marco Daniel, egreg, percusse, Paulo Cereda Jan 8 '12 at 18:40

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

3 Answers

up vote 5 down vote accepted

You may try the following. In the code, the file can is your image.

\documentclass{article}

\usepackage{tikz}

\begin{document}

\begin{tikzpicture}

\node at (5,5) {\includegraphics[scale=0.5]{can}};

%to help place things, draw a grid
%remove grid when done
\draw (0,0) grid (10,10);

\draw (5,5) -- ++(4,0) node[above=5pt,anchor=south east,inner sep=0] {this is a label};

\end{tikzpicture}

\end{document}

The result is

enter image description here

share|improve this answer

Because your image already has annotations, I use the following image as an example.

enter image description here

Then I converted it to EPS (named as grenade.eps) using ImageMagick.

\documentclass{article}
\usepackage{pstricks-add}
\usepackage[tightpage,active]{preview}
\setlength{\PreviewBorder}{12pt}
\PreviewEnvironment{pspicture}

\usepackage{graphicx}
\newsavebox\ImageBox
\savebox\ImageBox{\includegraphics[width=0.9\linewidth]{grenade}}

\newcommand\Rows{5}
\newcommand\Columns{5}

\newpsstyle{gridstyle}
{
    subgridcolor=green!20,
    subgridwidth=0.05pt,
    gridcolor=cyan!30,
    gridwidth=0.1pt,
    subgriddiv=2,
}

\psset
{
    xunit=\dimexpr\wd\ImageBox/\Rows\relax,
    yunit=\dimexpr\ht\ImageBox/\Columns\relax,
    style=gridstyle,
    nodesepA=3pt,
    linecolor=red,
}

\begin{document}

\begin{pspicture}(-\wd\ImageBox,0)(\wd\ImageBox,\ht\ImageBox)
\rput[b](0,0){\usebox\ImageBox}
\psgrid
% Pull Ring
\psComment[ref=l,angleA=180](4,3)(1.9,3.5){\large Pull Ring}[\ncdiagg]
% Safety Pin
\psComment[ref=l,angleA=180](4,4.8)(0.95,4.4){\large Safety Pin}[\ncdiagg]
% Body
\psComment[ref=r](-4,4)(0,2){\large Body}[\ncdiagg]
\end{pspicture}
\end{document}

enter image description here

Don't forget to compile the source code either with xelatex or latex-dvips-ps2pdf sequence.

Turn on the \psgrid to get a grid plus labels as follows.

enter image description here

You might need them to find the node coordinates during the development.

share|improve this answer
2  
pstricks-add knows \psComment*[ref=r]{->}(x,y)(x,y){Label}[\ncdiag] – Herbert Jan 8 '12 at 17:07
@Herbert: The code has been edited using \psComment. – Click Me Jan 8 '12 at 17:43
Will this work only with eps files? – Yiannis Lazarides Jan 8 '12 at 17:53
@YiannisLazarides: with xelatex you can also use png, pdf, and jpg. In short: every possible image for latex or pdflatex – Herbert Jan 8 '12 at 18:08
1  
@Herbert Thanks.I am still trying to get familiar with pstricks. No doubt that this is a much superior answer to the TikZ offered above. – Yiannis Lazarides Jan 8 '12 at 18:35

In this answer I tried to mimic the labels given by the questioner.

\documentclass{article}
\usepackage{pstricks-add}
\usepackage[tightpage,active]{preview}
\setlength{\PreviewBorder}{12pt}
\PreviewEnvironment{pspicture}

\usepackage{graphicx}
\newsavebox\ImageBox
\savebox\ImageBox{\includegraphics[width=0.9\linewidth]{grenade.eps}}

\newcommand\Rows{5}
\newcommand\Columns{5}

\newpsstyle{gridstyle}
{
    subgridcolor=green!20,
    subgridwidth=0.05pt,
    gridcolor=cyan!30,
    gridwidth=0.1pt,
    subgriddiv=2,
}

\psset
{
    xunit=\dimexpr\wd\ImageBox/\Rows\relax,
    yunit=\dimexpr\ht\ImageBox/\Columns\relax,
    style=gridstyle,
    linecolor=red,
}

\def\mylabel(#1,#2,#3)[#4][#5][#6]{
    \dotnode(#1,#3){#4start}
    \pnode(#2,#3){#4stop}
    \ncline{#4start}{#4stop}
    \rput[#6](#4stop){\large #5}
}
\begin{document}

\begin{pspicture}(-\wd\ImageBox,0)(\wd\ImageBox,\ht\ImageBox)
\rput[b](0,0){\usebox\ImageBox}
%\psgrid
% Pull Ring
\mylabel(1.9,4,3.5)[pr][Pull Ring][br]
% Safety Pin
\mylabel(0.95,4,4.4)[sp][Safety Pin][br]
% Body
\mylabel(0,-4,2)[b][Body][bl]
\end{pspicture}
\end{document}

enter image description here

share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.