5

I would like to comment a variable inside a boxed equation with an arrow (like the picture a), I hope someone could help me.

I used to comment the equation by an under/over-brace, but if there is too many text, the equation will be given a large space (like the picture b). If this problem could be solved also, I would be very grateful. enter image description here

SLN
  • 715

2 Answers2

6

This seems like a job for tikzmark:

\documentclass{article}
\usepackage{amsmath}
\usepackage{tikz}
\usetikzlibrary{tikzmark}

\begin{document}

\[
\boxed{F_{\tikzmark{a}1,n}= ...}
\]

\begin{tikzpicture}[remember picture,overlay]
\draw[->] ([xshift=2pt,yshift=-1pt]pic cs:a) -- ++(-45:20pt) coordinate (aux);
\node[yshift=-8pt] at (aux) {we only consider 1 unknown.};
\end{tikzpicture}

\end{document} 

enter image description here

In the previous example I boxed the expression using \boxed from amsmath but if you want fancier results, you can build the box with TikZ or use the features from tcolorbox:

\documentclass{article}
\usepackage{amsmath}
\usepackage{tcolorbox}
\usepackage{tikz}
\usetikzlibrary{tikzmark}
\tcbuselibrary{most}

\begin{document}

\[
\tcbhighmath{F_{\tikzmark{a}1,n}= ...}
\]

\begin{tikzpicture}[remember picture,overlay]
\draw[->] ([xshift=2pt,yshift=-1pt]pic cs:a) -- ++(-45:20pt) coordinate (aux);
\node[yshift=-8pt] at (aux) {we only consider 1 unknown.};
\end{tikzpicture}

\end{document} 

enter image description here

Gonzalo Medina
  • 505,128
3

Adapting my answer at Graphics equations: put text on equations

\documentclass{article}
\usepackage{graphicx}
\usepackage[usestackEOL]{stackengine}
\usepackage{xcolor}
\def\calloutsym{%
  \ensurestackMath{%
  \scalebox{1.7}{\color{red}\stackunder[0pt]{\bigcirc}{\downarrow}}}%
}
\newcommand\callouttext[1]{%
  \def\stacktype{S}\renewcommand\useanchorwidth{T}\stackText%
  \stackunder{\calloutsym}{\scriptsize\Longstack{#1}}\stackMath%
}
\newcommand\callout[3][1.5pt]{%
  \def\stacktype{L}\stackMath\stackunder[#1]{#2}{\callouttext{#3}}%
}
\begin{document}
\fbox{$\displaystyle
\smash{\callout{F}{\stackunder{$1,n$}{we only consider 1 unknown}}} = 
\left[
\frac{\partial f}{\partial l_1}\quad
\frac{\partial f}{\partial l_2}\quad
\frac{\partial f}{\partial l_3}
\cdots
\frac{\partial f}{\partial l_n}
\right]
$}
\end{document}

enter image description here

If you don't like the circle around the "F", remove \bigcirc, and perhaps scalebox the downarrow larger, as follows:

\documentclass{article}
\usepackage{graphicx}
\usepackage[usestackEOL]{stackengine}
\usepackage{xcolor}
\def\calloutsym{%
  \ensurestackMath{%
  \scalebox{2}{\color{red}\stackunder[2pt]{}{\downarrow}}}%
}
\newcommand\callouttext[1]{%
  \def\stacktype{S}\renewcommand\useanchorwidth{T}\stackText%
  \stackunder{\calloutsym}{\scriptsize\Longstack{#1}}\stackMath%
}
\newcommand\callout[3][1.5pt]{%
  \def\stacktype{L}\stackMath\stackunder[#1]{#2}{\callouttext{#3}}%
}
\begin{document}
\fbox{$\displaystyle
\smash{\callout{F}{\stackunder{$1,n$}{we only consider 1 unknown}}} = 
\left[
\frac{\partial f}{\partial l_1}\quad
\frac{\partial f}{\partial l_2}\quad
\frac{\partial f}{\partial l_3}
\cdots
\frac{\partial f}{\partial l_n}
\right]
$}
\end{document}

enter image description here

Note that since I smashed the underset, you may need some \vspace to prevent subsequent text from interfering.