4

I try desperately to make a macro which allows me to simply add a circled number with connector on a figure. To do that, I try to use into the command \put of overpic a tikz function which makes the job. I actually get a circled number with a connector on the figure but it seems that the bottom left of the tikz drawing box has a positive offset on the position given for a given value in \put{} of the overpic package. Here to make obvious the offset, I want to have my connector at (0,0).

In addition, this offset is picture scale sensitive. That is the reason why I put twice the picture with different size as an example in the dummy code below.

If in addition, the legend connector could remain proportional to the figure size it could be also great.

Actually my dream macro would be: specifying a coordinate for the connector tip, a connector angle, a connector length (in percentage of the picture width for example) and text (here a circled number).

If there is a dedicated package for doing that it would be even better. I can not imagine I am the only one who wants to do that...

One may suggest to do directly everything in tikz. But as I already have used overpic for other graphics, if I can avoid changing everything it would be great.

Thank you very much in advance!!

I put the dummy code here, you can use any graphic to test it.

    % !TEX TS-program = pdflatex

\documentclass[10pt]{article}

\usepackage{graphicx}
\usepackage{caption}
\DeclareGraphicsRule{.tif}{png}{.png}{`convert #1 `dirname #1`/`basename #1 .tif`.png}

%% Concerned packages:
\usepackage[percent]{overpic}
\usepackage{tikz}
%%





\title{Title}
\author{Name}
\begin{document}
\maketitle



\begin{figure}[htbp]
\centering
\begin{overpic}[width=1\columnwidth,grid,tics=5]{example-image-a} %,grid,tics=5
\put(0,0){
\begin{tikzpicture}
\path (0,0) node (x) {}
         (0.5,0.5) node[circle,draw](y){1};
\draw[black] (x) -- (y);
\end{tikzpicture}}
\end{overpic};
\caption{Picture with the legend added with the overpic and tikz package.}
\label{fig:mouse}
\end{figure}

\begin{figure}[htbp]
\centering
\begin{overpic}[width=0.7\columnwidth,grid,tics=5]{example-image-a} %,grid,tics=5
\put(0,0){
\begin{tikzpicture}
\path (0,0) node (x) {}
         (0.5,0.5) node[circle,draw](y){1};
\draw[black] (x) -- (y);
\end{tikzpicture}}
\end{overpic};
\caption{Picture with the legend added with the overpic and tikz package.}
\label{fig:mouse}
\end{figure}


\end{document}  
1

1 Answer 1

3

You don't need overpic actually. You can do it just using Tikz. But we need to modify your code as follows:

  1. Both the image (I used an example one) and the node go inside a tikzpicture.
  2. You can combine the \draw and the \node, no need to specify both.
  3. The image will be inside a \includegraphics, which in turn will be inside of a node itself, with the anchor on the south west and 0 for both inner sep and outer sep.

Now the south west is (0,0).

Output

figure 1

Some detail

figure 2

Code

\documentclass[10pt]{article}
\usepackage{tikz}
\usepackage{graphicx}
\usepackage{caption}
\DeclareGraphicsRule{.tif}{png}{.png}{`convert #1 `dirname #1`/`basename #1 .tif`.png}

\title{Title}
\author{Name}

\newcommand{\note}[3]{
    \node[circle,draw] (#3) at (#2)  {#3};
    \draw (#1) -- (#3);
}

\begin{document}
\maketitle

\begin{figure}[htbp]
\centering
\begin{tikzpicture}
\node[anchor=south west, inner sep=0, outer sep=0] {\includegraphics[width=1\columnwidth]{example-image-a}}; %,grid,tics=5
\note{0,0}{.5,.5}{1}
\end{tikzpicture}
\caption{CAD of a mouse with the legend added with the overpic and tikz package.}
\label{fig:mouse}
\end{figure}
\end{document}  
0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .