14

I want to create an equation with highlighting as shown bellow.

desired format
But using following code:

\documentclass[10pt,a4paper]{article}  
\usepackage[utf8]{inputenc}  
\usepackage{amsmath}  
\usepackage{amsfonts}  
\usepackage{amssymb}   
\usepackage{graphicx}
\usepackage{tikz}  
\usetikzlibrary{arrows,shapes,trees,positioning}  
\author{Apurba Paul}  
\begin{document}
\newcommand{\tikzmark}[1]{\tikz[baseline,remember picture] \node (#1) {};} 
\tikzset{square arrow/.style={to path={-- ++(-10,-.25) -| (\tikztotarget)}}}  

\begin{gather*}  
  y=\left[\frac{a}{\tikzmark{a}b}\frac{c}{\tikzmark{b}d}\right]\\  
  \tikz[remember picture]{\node(c){1'st part};}\qquad
  \tikz[remember picture]{\node(d){2'nd picture};}
  \tikz{\draw[->](a.south)to (c.north);}
  \tikz{\draw[->](b.south)to (d.north);}   
\end{gather*}  
\end{document}

But I am getting this enter image description here

2
  • It would be great to hace something simple like "underbrace" but with an arrow instead of a brace would be great, instad of a long and confusing code. a\cdot \underbrace{a}_{b\text{ times}}\cdots a $a\cdot \underbrace{a}_{b\text{ times}}\cdots a$
    – skan
    Oct 18, 2015 at 11:19
  • Crosslink to related question (in case someone come across this question), Graphics equations: put text on equations - TeX - LaTeX Stack Exchange
    – user202729
    Jan 18 at 22:20

4 Answers 4

12

Add the options remember picture and overlay to the connecting drawing commands:

\documentclass[10pt,a4paper]{article}  
\usepackage[utf8]{inputenc}  
\usepackage{amsmath}  
\usepackage{amsfonts}  
\usepackage{amssymb}   
\usepackage{graphicx}
\usepackage{tikz}  
\usetikzlibrary{arrows,shapes,trees,positioning}  
\author{Apurba Paul}  
\begin{document}

\newcommand{\tikzmark}[1]{\tikz[baseline,remember picture] \coordinate (#1) {};}

\tikzset{
  square arrow/.style={
    to path={-- ++(-10,-.25) -| (\tikztotarget)}
  }
}

\begin{gather*}  
  y=\left[\frac{a}{\tikzmark{a}b}\frac{c}{\tikzmark{b}d}\right]\\[2ex]
  \tikz[remember picture]{\node(c){1'st part};}\qquad
  \tikz[remember picture]{\node(d){2'nd picture};}
  \tikz[remember picture,overlay]{
    \draw[->] (a.south)++(.25em,-.3ex) to (c.north) ;
    \draw[->] (b.south)++(.25em,-.3ex) to (d.north) ;
  }  
\end{gather*}  
\end{document}

enter image description here

6

Without tikz:

\documentclass{article}
\usepackage{MnSymbol}
\usepackage{stackengine}
\renewcommand\useanchorwidth{T}
\usepackage{graphicx}
\stackMath
\begin{document}
\[
y = \bigg[
  \def\stackalignment{r}
  \stackunder{%
    \stackunder{\displaystyle\frac{a}{b}}{\scalebox{2}{$\swarrow$}\,}%
    }{\scriptstyle\mathsf{First~Part}~~}
  \def\stackalignment{l}
  \stackunder{%
    \stackunder{\displaystyle\frac{c}{d}}{\,\,\scalebox{2}{$\searrow$}}%
    }{\scriptstyle~~\mathsf{Second~Part}}
\bigg]
\]
\end{document}

enter image description here

And if you wished to do it without the MnSymbol package, you could use \rotatebox to get the tilted arrow:

\documentclass{article}
\usepackage{stackengine}
\renewcommand\useanchorwidth{T}
\usepackage{graphicx}
\stackMath
\begin{document}
\[
y = \bigg[
  \def\stackalignment{r}
  \stackunder{%
    \stackunder{\displaystyle\frac{a}{b}}{%
      \scalebox{1.5}{\rotatebox{-30}{$\downarrow$}}\,}%
    }{\scriptstyle\mathsf{First~Part}~~}
  \def\stackalignment{l}
  \stackunder{%
    \stackunder{\displaystyle\frac{c}{d}}{%
      \,\scalebox{1.5}{\rotatebox{30}{$\downarrow$}}}%
    }{\scriptstyle~~\mathsf{Second~Part}}
\bigg]
\]
\end{document}

enter image description here

3
  • While compiling I am getting error with '\stackMath. Error is stackMath.sty not found`
    – Apurba
    Nov 19, 2013 at 11:51
  • 1
    @Apurba stackMath is not a package name, but a command macro of the stackengine package. Does your source code erroneously state \usepackage{stackMath}, instead of \stackMath? Nov 19, 2013 at 11:54
  • Yes that was the problem and after installing stackengine it is working.
    – Apurba
    Nov 19, 2013 at 12:18
5

Just for fun with PSTricks.

\documentclass[preview,border=12pt,12pt]{standalone}% change it back to your own document class
\usepackage{amsmath}
\usepackage{pst-node}

\begin{document}
$
\displaystyle
\!
\begin{gathered}
y = [\rnode[b]{L}{\frac{a}{b}}\rnode[b]{R}{\frac{c}{d}}]\\[12pt]
\rnode[t]{LT}{\text{First part}}\qquad \rnode[t]{RT}{\text{Second part}}
\psset{nodesep=3pt,arrows=->}
\ncline{L}{LT}\ncline{R}{RT}
\end{gathered}
$
\end{document}

enter image description here

1
  • Hi. I get errors such as "Undefined control sequence. \ncline{L}{LT}" and "Undefined control sequence. \pgfsyspdfmark" and "\psset unrecognized command"
    – skan
    Oct 16, 2015 at 22:11
1

You can create an empty picture and use the overpic package to put the different components on specific places in the picture.

At first: create a white empty picture with arbitrarily size, name it empty.jpg and then put it in the same folder like your tex file.

Below is the MWE. You have just to play arround with the coordinates. But beware: there are two coordinate systems. The one from overpic, and the one from tikz.

\documentclass{article}  
\usepackage{subfigure}    
\usepackage{overpic}  
\usepackage{tikz} 


\begin{document}  

\begin{figure}    
\centering  
\subfigure{  
\begin{overpic}[width=5cm,height=5cm]{empty.jpg}\label{eq:equation1}  
\put(45,50){  $y=\left[\frac{a}{b}\frac{c}{d}\right]$ }  
\put(45,30){  

\begin{tikzpicture}[scale=0.1]  
\draw[->,thin] (0,0) -- (-5,-5);   
\draw[->,thin] (2,0) -- (7,-5);  
\end{tikzpicture}       }  

\put(20,20){1'st part}  
\put(60,20){2'nd picture}  

\end{overpic}           }  
\end{figure}  
\end{document}  
2
  • Maybe a MWE would help the OP. For me, this is more like a comment than an answer as it is not elaborate.
    – azetina
    Nov 18, 2013 at 19:14
  • Instead of (mis-)using overpic here with no real image, you could use the picture environment directly. This standard LaTeX environment is used by overpic internally. However, I would recommend the much newer TikZ package for this. With it you can declare certain parts as nodes and refer to its coordinates afterwards. Nov 18, 2013 at 20:55

You must log in to answer this question.

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