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

  • 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 '15 at 11:19
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

  • While compiling I am getting error with '\stackMath. Error is stackMath.sty not found` – Apurba Nov 19 '13 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? – Steven B. Segletes Nov 19 '13 at 11:54
  • Yes that was the problem and after installing stackengine it is working. – Apurba Nov 19 '13 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

  • Hi. I get errors such as "Undefined control sequence. \ncline{L}{LT}" and "Undefined control sequence. \pgfsyspdfmark" and "\psset unrecognized command" – skan Oct 16 '15 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}  
  • 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 '13 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. – Martin Scharrer Nov 18 '13 at 20:55

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.