4

I would like to be able to access the sides of a matrix.

My issue is a that a tikzmark placed between a = sign and a matrix gives wrong spacing.

I get the first output line spacing when I would like the third one. How to fix that ?

Output

enter image description here

MWE

\documentclass{article}
\usepackage{mathtools}
\usepackage{tikz}
\usetikzlibrary{tikzmark}
\begin{document}
\setlength\parindent{0pt}
  $
  A
  =
  \tikzmark{gauche}
  \begin{bmatrix}
    1 & 2 & 3 \\ 
    3 & 5 & 6 \\ 
    1 & 2 & 3 \\ 
  \end{bmatrix}
  $ the \verb|\tikzmark| is grabbed by \verb|{#1}={#2}| : gives wrong spacing

  $
  A
  =
  {}
  \begin{bmatrix}
    1 & 2 & 3 \\ 
    3 & 5 & 6 \\ 
    1 & 2 & 3 \\ 
  \end{bmatrix}
  $ as if there was a \verb|{}| after the \verb|=|

  $
  A
  =
  \begin{bmatrix}
    1 & 2 & 3 \\ 
    3 & 5 & 6 \\ 
    1 & 2 & 3 \\ 
  \end{bmatrix}
  $ for reference : what I would like.
\end{document}

Cheers,

5

You can use

  \mathopen{\tikzmark{gauche}}

then the spacing is controlled by the tikzmark, an and the second open from the matrix does not add extra space when following the mathopen.

  • Thank you. So \mathopen{\whatever} has TeX treat \whatever as an opening delimiter ; is this right ? It's an analogue to the \mathbin command ? – marsupilam Apr 1 '17 at 18:26
  • @marsupilam it's an exact analogue of \mathbin (and controls just horizontal space) it doesn't give the other features of delimiters, stretching or mathinner from \left\right. – David Carlisle Apr 1 '17 at 18:58
  • Is this the sort of thing that tikzmark should do automatically? Or are there too many cases to consider? – Loop Space Apr 1 '17 at 19:12
3

There is unfortunately no general rule for this.

A bmatrix makes an “inner atom”, while \tikzmark inserts an empty subformula that counts as an ordinary atom.

By rule, TeX inserts a thin space (more precisely a \thinmuskip) between an ordinary and an inner atom. In other cases, when \tikzmark sits next to another ordinary atom (a single letter or number, generally), no space is added.

For the special case, you can remove the added space by adding \! between \tizkmark{gauche} and \begin{bmatrix}.

Another strategy is to globally remove the added space with inner atoms (essentially \left\right pairs) by using mleftright.

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

\begin{document}
\setlength\parindent{0pt}
  $
  A
  =
  \tikzmark{gauche}\!
  \begin{bmatrix}
    1 & 2 & 3 \\ 
    3 & 5 & 6 \\ 
    1 & 2 & 3 \\ 
  \end{bmatrix}
  $ the \verb|\tikzmark| now gives right spacing

  $
  A
  =
  {}
  \begin{bmatrix}
    1 & 2 & 3 \\ 
    3 & 5 & 6 \\ 
    1 & 2 & 3 \\ 
  \end{bmatrix}
  $ here there is a \verb|{}| after the \verb|=|

  $
  A
  =
  \begin{bmatrix}
    1 & 2 & 3 \\ 
    3 & 5 & 6 \\ 
    1 & 2 & 3 \\ 
  \end{bmatrix}
  $ for reference: what I would like.
\end{document}

enter image description here

Now with mleftright and \mleftright in the preamble. Note that, in this case, the spacing is right also with {}.

\documentclass{article}
\usepackage{mathtools,mleftright}
\usepackage{tikz}
\usetikzlibrary{tikzmark}

\mleftright

\begin{document}
\setlength\parindent{0pt}
  $
  A
  =
  \tikzmark{gauche}
  \begin{bmatrix}
    1 & 2 & 3 \\ 
    3 & 5 & 6 \\ 
    1 & 2 & 3 \\ 
  \end{bmatrix}
  $ the \verb|\tikzmark| now gives right spacing

  $
  A
  =
  {}
  \begin{bmatrix}
    1 & 2 & 3 \\ 
    3 & 5 & 6 \\ 
    1 & 2 & 3 \\ 
  \end{bmatrix}
  $ here there is a \verb|{}| after the \verb|=|

  $
  A
  =
  \begin{bmatrix}
    1 & 2 & 3 \\ 
    3 & 5 & 6 \\ 
    1 & 2 & 3 \\ 
  \end{bmatrix}
  $ for reference: what I would like.
\end{document}

enter image description here

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.