0

I've created matrices with some diagonal lines and some tweaking on \vdots. (based on these posts: diagonal line within matrix and How to vertically center the \vdots in this node? )

The result is exactly what I want, but when I copy the code from my test/trial&error file to my main file I encounter a problem. After some searching I've located the issue: without the tikzexternal command everything works fine.

However, my main file is rather large so I cant really go without the tikzexternal command.

Can someone fix this for me? (and explain what the problem is?) Just uncomment the 3 tikzexternalize lines to reproduce the error.

(maybe relevant: with the tikzexternalize enabled I get different errors in each document, let me know if you need the actual error messages)

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

%\usepgfplotslibrary{external} %use with --shell-escape
%\tikzexternalize[prefix=Tikzplots/]
%\pgfplotsset{compat=newest}

\makeatletter               %vdots without extra space on top
\DeclareRobustCommand{\rvdots}{%
    \vbox{
        \baselineskip4\p@\lineskiplimit\z@
        \kern-\p@
        \hbox{.}\hbox{.}\hbox{.}
}}
\makeatother


\newcommand\tikzmark[1]{%       %nodes in matrix for lines
    \tikz[overlay,remember picture,baseline] \node [anchor=base] (#1) {};}

\newcommand\MyLine[3][]{%       %draw lines between the nodes^
    \begin{tikzpicture}[overlay,remember picture]
    \draw[#1] (#2.north west) -- (#3.east);
    \end{tikzpicture}}



\begin{document}

\[
\begin{bmatrix}
Y[1]\\
\phantom{0}\\
\rvdots\\
\rvdots\\
\phantom{0}\\
Y[k]
\end{bmatrix}
=
\begin{bmatrix}
\phantom{0}\tikzmark{a} & \phantom{0}& \phantom{0}& \phantom{0}&\phantom{0}& \phantom{0} \\
\\
\\
\\
\\
& & & & & \tikzmark{b}\phantom{0}
\end{bmatrix}
\cdot
\begin{bmatrix}
X[1]\\
\phantom{0}\\
\rvdots\\
\rvdots\\
\phantom{0}\\
X[k]
\end{bmatrix}
\]



\[
\begin{bmatrix}
Y[1]\\
\phantom{0}\\
\rvdots\\
\rvdots\\
\phantom{0}\\
Y[k]
\end{bmatrix}
=
\begin{bmatrix}
\phantom{0}\tikzmark{c} & \phantom{0} &\phantom{0}\tikzmark{e} &\phantom{0} & \phantom{0}\tikzmark{g}& \phantom{0}\\
& & & & &\tikzmark{h}\phantom{0}\\
\phantom{0}\tikzmark{i}& & & & &\\
& & & & & \tikzmark{f}\phantom{0} \\
\phantom{0}\tikzmark{k}& & & & &\\
&\tikzmark{l}\phantom{0} & &\tikzmark{j}\phantom{0} & & \tikzmark{d}\phantom{0}\\
\end{bmatrix}
\cdot
\begin{bmatrix}
X[1]\\
\phantom{0}\\
\rvdots\\
\rvdots\\
\phantom{0}\\
X[k]
\end{bmatrix}
\] 
\MyLine[thick]{a}{b}
\MyLine[red,thick]{c}{d}
\MyLine[thick]{e}{f}
\MyLine[thick]{g}{h}
\MyLine[thick]{i}{j}
\MyLine[thick]{k}{l}
\end{document}
  • 1
    I suggest adding \tikzexternaldisable and \tikzexternalenable to both commands – JBantje Oct 12 '17 at 21:08
  • How exactly? Because the following doesnt work: \tikzexternaldisable \newcommand\tikzmark[1]{% %nodes in matrix for lines \tikz[overlay,remember picture,baseline] \node [anchor=base] (#1) {};} \tikzexternalenable – Niwol Oct 12 '17 at 21:12
  • See my answer ;-) They have to be included in the command's body – JBantje Oct 12 '17 at 21:14
2

If one adds \tikzexternaldisable and tikzexternalenable at the appropriate places (and adds the missing pgfplots-package) it works fine for me:

\documentclass{article}
\usepackage{amsmath}
\usepackage{tikz}
\usepackage{pgfplots}

\usepgfplotslibrary{external} %use with --shell-escape
\tikzexternalize[prefix=Tikzplots/]
\pgfplotsset{compat=newest}

\makeatletter               %vdots without extra space on top
\DeclareRobustCommand{\rvdots}{%
    \vbox{
        \baselineskip4\p@\lineskiplimit\z@
        \kern-\p@
        \hbox{.}\hbox{.}\hbox{.}
}}
\makeatother


\newcommand\tikzmark[1]{%       %nodes in matrix for lines
    \tikzexternaldisable\tikz[overlay,remember picture,baseline] \node [anchor=base] (#1) {};\tikzexternalenable}

\newcommand\MyLine[3][]{%       %draw lines between the nodes^
    \tikzexternaldisable
    \begin{tikzpicture}[overlay,remember picture]
    \draw[#1] (#2.north west) -- (#3.east);
    \end{tikzpicture}\tikzexternalenable}



\begin{document}

\[
\begin{bmatrix}
Y[1]\\
\phantom{0}\\
\rvdots\\
\rvdots\\
\phantom{0}\\
Y[k]
\end{bmatrix}
=
\begin{bmatrix}
\phantom{0}\tikzmark{a} & \phantom{0}& \phantom{0}& \phantom{0}&\phantom{0}& \phantom{0} \\
\\
\\
\\
\\
& & & & & \tikzmark{b}\phantom{0}
\end{bmatrix}
\cdot
\begin{bmatrix}
X[1]\\
\phantom{0}\\
\rvdots\\
\rvdots\\
\phantom{0}\\
X[k]
\end{bmatrix}
\]



\[
\begin{bmatrix}
Y[1]\\
\phantom{0}\\
\rvdots\\
\rvdots\\
\phantom{0}\\
Y[k]
\end{bmatrix}
=
\begin{bmatrix}
\phantom{0}\tikzmark{c} & \phantom{0} &\phantom{0}\tikzmark{e} &\phantom{0} & \phantom{0}\tikzmark{g}& \phantom{0}\\
& & & & &\tikzmark{h}\phantom{0}\\
\phantom{0}\tikzmark{i}& & & & &\\
& & & & & \tikzmark{f}\phantom{0} \\
\phantom{0}\tikzmark{k}& & & & &\\
&\tikzmark{l}\phantom{0} & &\tikzmark{j}\phantom{0} & & \tikzmark{d}\phantom{0}\\
\end{bmatrix}
\cdot
\begin{bmatrix}
X[1]\\
\phantom{0}\\
\rvdots\\
\rvdots\\
\phantom{0}\\
X[k]
\end{bmatrix}
\] 
\MyLine[thick]{a}{b}
\MyLine[red,thick]{c}{d}
\MyLine[thick]{e}{f}
\MyLine[thick]{g}{h}
\MyLine[thick]{i}{j}
\MyLine[thick]{k}{l}
\end{document}
  • Wow yes perfect!!! That was rather simple :) – Niwol Oct 12 '17 at 21:19

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.