This question already has an answer here:

I have a matrix A, described using an environment bmatrix as in the MWE below.


Consider the matrix 
1 & 0 & -1 \\ 
2 & 3 & 1  \\  

Then its transpose is 
1 & 2 \\
0 & 3\\ 
-1 & 1  \\  


How can I get the transpose of A without typing all its entries? In other word, is there an environment where \ means "end of column" instead of "end of row"?

I hope I could just paste and copy the definition of A and then change bmatrix to vbmatrix or whatever.

marked as duplicate by Fran, Zarko, gernot, egreg, Steven B. Segletes Mar 20 '17 at 10:08

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.


A solution is to save the matrix in some unique name, then to reuse this matrix while rotating it at the same time.

Note that (see why here) you can not use a simple ampersand as a separator when using a command to typeset matrices with tikz.

Note also that the last \\ is mandatory (otherwise you will get a missing } error).



  \global\expandafter\def\csname mycustommatrixnamed#1\endcsname{#2}
  \left [ \begin{tikzpicture}[baseline=-0.5ex]
    \matrix[matrix of math nodes, ampersand replacement=\&] { \csname mycustommatrixnamed#1\endcsname };
  \end{tikzpicture} \right ]

  \left [ \rotatebox[origin=c]{90}{\reflectbox{ \begin{tikzpicture}[baseline=-0.5ex]
    \matrix[matrix of math nodes, ampersand replacement=\&, nodes={rotate=90,xscale=-1}] { \csname mycustommatrixnamed#1\endcsname };
  \end{tikzpicture} }} \right ]


$A = \mycustommatrix{A}{
  1 \& 0 \& -1 \\
  2 \& 3 \& 1 \\

$A^T = \mycustomtranspose{A}$



Not the answer you're looking for? Browse other questions tagged or ask your own question.