1

This question already has an answer here:

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

\documentclass{article}

\begin{document}
Consider the matrix 
$A=\begin{bmatrix} 
1 & 0 & -1 \\ 
2 & 3 & 1  \\  
\end{bmatrix}$

Then its transpose is 
$A^T=\begin{bmatrix} 
1 & 2 \\
0 & 3\\ 
-1 & 1  \\  
\end{bmatrix}$

\end{document}

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.

3

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).

\documentclass{standalone}

\usepackage{tikz}
\usetikzlibrary{matrix}

\newcommand{\mycustommatrix}[2]{
  \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 ]
}

\newcommand{\mycustomtranspose}[1]{
  \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 ]
}

\begin{document}

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

$A^T = \mycustomtranspose{A}$

\end{document}

Result

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