2

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}  
2

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}  
  • Hi @Alenanno thank you for you fast response. I guess I can not avoid leaving the overpic environnement I used for many picture before. I now also know there is a dummy picture in latex. ;-) I would ideally have the connector starting from the circle and not the center. I think I have to use the "pin" option. – Willi Jul 3 '15 at 14:50
  • @Willi I fixed the connection of the path to the edge. I understand you have used overpic before, but I think you're unnecessarily complicating your workflow. – Alenanno Jul 3 '15 at 14:57
  • I just tried your example and it works fine. I still have the problem that the connector is not picture scale sensitive. In addition, I would like to have a "dynamic anchor" it is to say that in some case the connector orientation has to change and must not overlap the legend. I don't know if it is possible. Anyway I validate your answer for the offset problem. :-) – Willi Jul 3 '15 at 15:04
  • @Willi I have some doubts: 1) what do you mean about picture scale sensitive? 2) if you decide to go into the negative Y, the note will overlap the legend. You could change this by increase the space between the image and legend, but it all depends on the cases you will face in the future. – Alenanno Jul 3 '15 at 15:16
  • 1) it means that if I change the width of the picture, the connector size remains the same which kills the fine text placing tuning. 2) for the orientation of the connector there is no overlapping unless the connector is small so actually it is not a real issue. For the scaling problem, maybe introducing a variable which appears in the picture width and in the macro will help to solve the problem but I don't figure how to do that. – Willi Jul 3 '15 at 15:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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