# Horizontal stretching of pmatrix

I have the following code to generate a pmatrix:

\documentclass{article}
\usepackage[utf8]{inputenc}

\usepackage{amsmath}
\usepackage{mathtools}
\usepackage{graphicx}

\renewcommand\arraystretch{2}

\begin{document}

\
$$\begin{pmatrix} 2 & 1 & 0 & 0 & 1 & 0 \\ 1 & 0 & 1 & 0 & 1 & 0 \\ 0 & 1 & 0 & 1 & 0 & 0 \\ 0 & 0 & 1 & 0 & 1 & 1 \\ 1 & 1 & 0 & 1 & 0 & 0 \\ 0 & 0 & 0 & 1 & 0 & 0 \end{pmatrix}$$

\end{document}


It currently looks like this:

Now I want to stretch the matrix both horizontally and vertically in such a way such that it covers most of the page area. How can I do this?

You can play with \arraycolsep, and to ensure a proper spacing between the contents of the matrix and the parentheses, you can nest a matrix environment, surrounded by a pair of horizontal spaces, in a pmatrix environment, like this:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{mathtools}

\begin{document}

$\setlength{\arraycolsep}{10pt} \renewcommand\arraystretch{2} \begin{pmatrix} \hspace {0.7em} \begin{matrix} 2 & 1 & 0 & 0 & 1 & 0 \\ 1 & 0 & 1 & 0 & 1 & 0 \\ 0 & 1 & 0 & 1 & 0 & 0 \\ 0 & 0 & 1 & 0 & 1 & 1 \\ 1 & 1 & 0 & 1 & 0 & 0 \\ 0 & 0 & 0 & 1 &0 & 0 \end{matrix} \hspace {0.7em} \end{pmatrix}$

\end{document}


• Sorry, how is that different from Alex' answer? – user121799 Jul 15 '18 at 16:51
• @marmot: Oops! I didn't see his answer. Apart from a few explanations details, you'tr right, it's the same. I'll delete it in a moment. – Bernard Jul 15 '18 at 16:54
• @marmot: I've modified my code to have a better spacing w.r.t. parentheses. – Bernard Jul 15 '18 at 17:13
• I am not a referee but must admit that I still can't see much of a difference in the code. Any chance that you were talking about nesting these things but forgot to do it in the actual code? – user121799 Jul 15 '18 at 17:17
• @marmot: Absolutely. A copy-paste accident. I've fixed it (should always re-read what I post to check…). – Bernard Jul 15 '18 at 17:28

Use \arraycolsep:

\documentclass{article}
\usepackage[utf8]{inputenc}

\usepackage{amsmath}
\usepackage{mathtools}
\usepackage{graphicx}

\begin{document}

\setlength{\arraycolsep}{10pt}.
\renewcommand\arraystretch{2}

$\begin{pmatrix} 2 & 1 & 0 & 0 & 1 & 0 \\ 1 & 0 & 1 & 0 & 1 & 0 \\ 0 & 1 & 0 & 1 & 0 & 0 \\ 0 & 0 & 1 & 0 & 1 & 1 \\ 1 & 1 & 0 & 1 & 0 & 0 \\ 0 & 0 & 0 & 1 & 0 & 0 \end{pmatrix}$

\end{document}


And also please un-learn , it's deprecated.

• You may want to mention that the default value of \arraycolsep is 5pt; hence, setting this length parameter to 10pt doubles the width between the columns. – Mico Jul 15 '18 at 17:02

One possibility is to use tabular*. Please see here for more options.

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\renewcommand\arraystretch{2}

\begin{document}

$\left(\vcenter{\hbox{\begin{tabular*}{0.85\textwidth}{@{\extracolsep{\fill}} *{6}{c}} 2 & 1 & 0 & 0 & 1 & 0 \\ 1 & 0 & 1 & 0 & 1 & 0 \\ 0 & 1 & 0 & 1 & 0 & 0 \\ 0 & 0 & 1 & 0 & 1 & 1 \\ 1 & 1 & 0 & 1 & 0 & 0 \\ 0 & 0 & 0 & 1 & 0 & 0 \end{tabular*}}}\right)$

\end{document}


The following code requires the number of columns; it automatically fills the \displaywidth.

\documentclass{article}
\usepackage{amsmath}
\usepackage{expl3}

\ExplSyntaxOn
\cs_set_eq:NN \replicate \prg_replicate:nn
\ExplSyntaxOff

\makeatletter
\newenvironment{bigpmatrix}[1]
{\left(\,
\settowidth\dimen@{$\Bigg(\,\,$}%
\vcenter to \displaywidth\bgroup
\def\\{\cr\noalign{\vfil}}%
\edef\preamble{\replicate{#1-2}{$####$\unskip&}}%
\tabskip=0pt
\medskip
\halign to \dimexpr \displaywidth-2\dimen@\bgroup
$##$\unskip\tabskip=0pt plus 1fil &
\span\preamble
$##$\unskip\tabskip0pt\cr
}{\crcr\egroup\medskip\egroup\,\right)}
\makeatother

\begin{document}

$\begin{bigpmatrix}{12} 2 & 1 & 0 & 0 & 1 & 0 & 1 & 0 & 1 & 0 & 1 & 0 \\ 0 & 1 & 0 & 1 & 0 & 0 & 0 & 0 & 1 & 0 & 1 & 1 \\ 1 & 1 & 0 & 1 & 0 & 0 & 0 & 0 & 0 & 1 & 0 & 0 \\ 2 & 1 & 0 & 0 & 1 & 0 & 1 & 0 & 1 & 0 & 1 & 0 \\ 0 & 1 & 0 & 1 & 0 & 0 & 0 & 0 & 1 & 0 & 1 & 1 \\ 1 & 1 & 0 & 1 & 0 & 0 & 0 & 0 & 0 & 1 & 0 & 0 \\ 2 & 1 & 0 & 0 & 1 & 0 & 1 & 0 & 1 & 0 & 1 & 0 \\ 0 & 1 & 0 & 1 & 0 & 0 & 0 & 0 & 1 & 0 & 1 & 1 \\ 1 & 1 & 0 & 1 & 0 & 0 & 0 & 0 & 0 & 1 & 0 & 0 \\ 2 & 1 & 0 & 0 & 1 & 0 & 1 & 0 & 1 & 0 & 1 & 0 \\ 0 & 1 & 0 & 1 & 0 & 0 & 0 & 0 & 1 & 0 & 1 & 1 \\ 1 & 1 & 0 & 1 & 0 & 0 & 0 & 0 & 0 & 1 & 0 & 0 \end{bigpmatrix}$

\end{document}


A TABstack allows both dimensions (column gap and row baselineskip) to be specified.

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{tabstackengine}
\stackMath
\begin{document}
$\setstackgap{L}{60pt} \setstacktabbedgap{60pt} \parenMatrixstack{ 2 & 1 & 0 & 0 & 1 & 0 \\ 1 & 0 & 1 & 0 & 1 & 0 \\ 0 & 1 & 0 & 1 & 0 & 0 \\ 0 & 0 & 1 & 0 & 1 & 1 \\ 1 & 1 & 0 & 1 & 0 & 0 \\ 0 & 0 & 0 & 1 & 0 & 0 }$
\end{document}


I believe you can use the TikZ package in the preamble and use amsmath as well. With this, use the scaling feature:

\usepackage{tikz} % in the preamble
\usepackage{amsmath} % in the preamble
\usetikzlibrary{matrix} % in the preamble
\begin{tikzpicture}[scale=.5]


However, I am not sure whether you need to set transform shape.