I want to write a matrix with equal column widths, plus have a vertical line down the matrix. By using the solutions given here and here, I have
\documentclass{article}
\usepackage{geometry}
\usepackage{amsmath}
\usepackage{graphicx}
% draw vertical line down matrix
\makeatletter
\renewcommand*\env@matrix[1][*\c@MaxMatrixCols c]{%
\hskip -\arraycolsep
\let\@ifnextchar\new@ifnextchar
\array{#1}}
\makeatother
\begin{document}
\resizebox{\linewidth}{!}{%
\begin{equation}
\begin{pmatrix}[cc|cc]
C1 & Column2 & C3 & C4 \\ \hline
C5 & C6 & C7 & Column8
\end{pmatrix}$%
\end{equation}
}
\end{document}
The output matrix does not have equal column widths, and I get an error Missing $ inserted
. How can I solve this problem?
Best Answer
Notes:
Missing $ inserted
is because of the single$
sign at\end{pmatrix}$%
.\resizebox{.9\hsize}{!}{%
inside the equation (see Scale an equation to fit exact page width).tabularx
to define a new columntypeC
, witch allows you to set the width of a centered entry by usingC{<width>}
.Code:
Result: