5

Is there perhaps a package that already does something like this?

In THIS topic encircling a formula is given, but I don't understand the syntax to modify the 'circle' to have an arrow point outward from somewhere.

The end goal is to have something like this.

image

I tried to use the example given in the linked topic as a base

\documentclass{article}

\usepackage{tikz}

\makeatletter
\newcommand*{\encircled}[1]{\relax\ifmmode\mathpalette\@encircled@math{#1}\else\@encircled{#1}\fi}
\newcommand*{\@encircled@math}[2]{\@encircled{$\m@th#1#2$}}
\newcommand*{\@encircled}[1]{%
  \tikz[baseline,anchor=base]{\node[draw,circle,outer sep=0pt,inner sep=.2ex] {#1};}}
\makeatother

\begin{document} not important at the  moment
\end{document}

There are a lot of embellishments that have something to do with preserving proper formating or some such. The core of the problem is to modify the \node[...] bit which results in a circle with an arrow pointing out from it, but I feel that's a dead-end.

  • Please help us help you and add a minimal working example (MWE) that illustrates your problem. Reproducing the problem and finding out what the issue is will be much easier when we see compilable code, starting with \documentclass{...} and ending with \end{document}. – albert Aug 5 '18 at 11:18
  • @Alvin_Lepik: Do you want the whole picture in TikZ or just the circled part – I'm confused, since I think I didn't understood your question … I thought you want a command which produces a circles node from which is pointing an arrow out and that all as a baseline-TikZ picture. – current_user Aug 5 '18 at 12:56
  • 1
    Judging from the various comments I think that what you need is the \tikznode approach where the positioning is done by TeX implicitly; see the second modified example in my answer. – gernot says Reinstate Monica Aug 5 '18 at 14:12
  • @gernot very elegant indeed, I appreciate also the links you added. I accepted your answer, instead as I feel it is more complete, not to take anything away from current_user. – Alvin Lepik Aug 5 '18 at 14:32
7

The best approach depends on whether your sketch is meant as a single image---in this case use a single tikzpicture environment---or whether the items appear mixed with text on a page---in this case use the \tikznode command from this post. Here are examples for both situations. Note that you have to run LaTeX twice on the second example.

Everything in a single picture: The position of the elements can be specified explicitly relative to each other.

enter image description here

\documentclass[border=1pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{positioning}
\begin{document}
\begin{tikzpicture}
  \node[circle,draw](fx){$f(x)$};
  \node(a)[below right=of fx]{$a$};
  \draw[->] (fx) -- (a);
\end{tikzpicture}
\end{document}

Graphical elements as part of text: The position of the elements is defined implicitly by the typesetting engine that positions the elements. For examples of the use of \tikznode see e.g. Breaking numbers Simple addition, How to add arrow in equations and matrix? or how can you point the head of an arrow from tikzpicture to an equation in LaTex?.

enter image description here

\documentclass{article}
\usepackage{tikz}
\newcommand\tikznode[3][]%
   {\tikz[remember picture,baseline=(#2.base)]
      \node[minimum size=0pt,inner sep=0pt,#1](#2){#3};%
   }
\begin{document}
\[ \frac{g(x)}{\tikznode[circle,draw]{fx}{$f(x)$}}
  =\frac{g(x)}{\tikznode{a}{$a$}}
\]
\begin{tikzpicture}[remember picture,overlay]
  \draw[->] (fx) edge[bend right] (a);
\end{tikzpicture}
\end{document}
  • I apologise for ambiguity, the downpointing arrow simply shows the output of \command{}{}. Regardless, the question is answered :) – Alvin Lepik Aug 5 '18 at 12:48
4

Maybe something like this?

\documentclass{article}
\usepackage{tikz,blindtext}
\newcommand{\mycircle}[2]{\begin{tikzpicture}[remember picture]
                            \node[draw,circle] (#2) {$#1$};
                            \draw[->] (#2) --+ (1,-1) node[below right] {$#2$};
                          \end{tikzpicture}
                         }
\begin{document}
    \blindtext\par
    \mycircle{f(x)}{a}\par
    \blindtext
\end{document}

Here is the output:

Screenshot

EDIT: The denominator isn't overlapped:

MWE:

\documentclass{article}
\usepackage{tikz,blindtext}
\newcommand{\mycircle}[2]{\begin{tikzpicture}[remember picture]
                            \node[draw,circle] (#2) {$#1$};
                            \draw[->] (#2.south east) --+ (1,-1) node[below right] {$#2$};
                          \end{tikzpicture}
                         }
\begin{document}
    \blindtext\par
    \mycircle{f(x)}{a}\par
    \[
        \frac{f(x)}{\mycircle{g(x)}{a}}
    \]
    \blindtext\par
\end{document}

Output:

Screenshot

  • you're right, overlapping was due to a box environment in which I was using the circling. – Alvin Lepik Aug 5 '18 at 13:26
  • @Alvin_Lepkik: Ahh, now I gotcha. – current_user Aug 5 '18 at 13:32

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.