1

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.

Taladris
  • 328
  • there is this, but I wouldn't use it, better to just get your editor to transpose http://tex.stackexchange.com/questions/75793/tabular-input-by-columns-i-e-transpose-a-table/75799#75799 – David Carlisle Mar 20 '17 at 07:40
  • You can find it here: http://tex.stackexchange.com/q/283081/124842. There are 2 possible answer – Bobyandbob Mar 20 '17 at 07:40

1 Answers1

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