1

I have two problems to solve withe the following TiKz code.

  1. I would like to use relative coordinates such as to have a wider blue rectangle. I have try to play with ++ without success.
  2. All my styles have common definitions. Is there a way to use a kind of substyle that will be used by all my styles ?

How can I solve this ?

\documentclass[12pt]{amsart}
\usepackage{tikz}
\usetikzlibrary{arrows, matrix, positioning}

\tikzset{
    % Good spacing hack (the ghost mode)
    gs/.style={
        rectangle,
        thick,
        text width=3em,
        align=center,
        draw=white,
        rounded corners,
        minimum height=2em
    },    % Focus effect
    fe/.style={
        rectangle,
        thick,
        rounded corners,
        minimum height=2em,
        text width=8em,
        align=center,
        draw=red,
        text=magenta
    },
    % Focus effect Bis
    feb/.style={
        rectangle,
        thick,
        rounded corners,
        minimum height=2em,
        text width=8em,
        align=center,
        draw=blue,
        text=violet
    },
    % Long focus effect
    lfe/.style={
        rectangle,
        thick,
        rounded corners,
        minimum height=2em,
        text width=12em,
        align=center,
        draw=red,
        text=magenta
    },
    % Long focus effect bis
    lfeb/.style={
        rectangle,
        thick,
        rounded corners,
        minimum height=2em,
        text width=12em,
        align=center,
        draw=blue,
        text=violet
    },
}


\begin{document}

\begin{tikzpicture}
    \matrix[matrix of nodes,
        row sep    = 1em,
        column sep = 1.5em,
    ](mat){
          & |[gs]|$a$ & |[gs]|$X$ \\
|[gs]|$q$ & |[gs]|$b$ & |[gs]|$Y$  \\
          & |[gs]|$r$ & |[gs]|$Z$  \\
    };

    \draw[fe] (mat-1-2.north west) -- (mat-1-3.north east)
           -- (mat-2-3.south east) -- (mat-2-2.south west)
           -- (mat-1-2.north west);

    \draw[red,-triangle 60] (mat-1-3.north east) -- ++ (0,-2.5em) |- ++ (3em,0)
               node[pos=2.05, lfe] (f){$aY - bX = d$};

    \draw[feb] (mat-2-2.north west) -- (mat-2-3.north east)
           -- (mat-3-3.south east) -- (mat-3-2.south west)
           -- (mat-2-2.north west);

    \draw[blue,-triangle 60] (mat-2-3.north east) -- ++ (0,-2.5em) |- ++ (3em,0)
               node[pos=2.05, lfeb] (f){$bZ - rY = e$};
\end{tikzpicture}

\end{document}
  • 1
    Common style: common/.style={ rectangle, thick, rounded corners, align=center, minimum height=2em }, gs/.style={common, text width=3em, draw=white, }, % Focus effect etc – AndréC Sep 11 '19 at 13:38
  • Such a shame ! I should have tried this. Sorry for the noise. The first point remains a problem for me. Thanks. – projetmbc Sep 11 '19 at 13:44
  • Is there a reason why you want to play with ++? Do you only want to do with ++? – AndréC Sep 11 '19 at 13:50
  • This is a way to learn to use it. – projetmbc Sep 11 '19 at 18:11
1

You could just draw the rectangles with fit. To make them larger, you could increase the inner sep.

\documentclass[12pt]{amsart}
\usepackage{tikz}
\usetikzlibrary{arrows, matrix, positioning,fit}

\tikzset{
    % Good spacing hack (the ghost mode)
     gs/.style={
        rectangle,
        thick,
        text width=3em,
        align=center,
        draw=white,
        rounded corners,
        minimum height=2em
    },    %
    rc/.style={rectangle,
        thick,rounded corners,draw},
    lfe/.style={rc,
        text width=12em,
        align=center,
        text=magenta
    },
    % Long focus effect bis
    lfeb/.style={rc,
        text width=12em,
        align=center,
        text=violet
    },
}


\begin{document}

\begin{tikzpicture}
    \matrix[matrix of nodes,nodes=gs,
        row sep    = 1em,
        column sep = 1.5em,
    ](mat){
          & $a$ & $X$ \\
$q$ & $b$ & $Y$  \\
          & $r$ & $Z$  \\
    };

    \node[fit=(mat-1-2) (mat-2-3),inner xsep=1em,rc,red] (F1){};

    \draw[red,-triangle 60] (F1.east) -- ++ (2.5em,0)
               node[right, lfe] (f){$aY - bX = d$};

    \node[inner xsep=2em,fit=(mat-2-2) (mat-3-3),rc,blue] (F2){};

    \draw[blue,-triangle 60] (F2.east) -- ++ (2.5em,0)
               node[right,lfeb] (f){$bZ - rY = e$};
\end{tikzpicture}

\end{document}

enter image description here

  • My learning of TikZ looks like a random quantum walk. Thanks for the help ! – projetmbc Sep 11 '19 at 14:14

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.