How to input the staggered array as the expression like this:
The expressions are in hexagonal fashion. Are there packages for this situation?
thank you.
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It only takes a minute to sign up.
Sign up to join this communityHow to input the staggered array as the expression like this:
The expressions are in hexagonal fashion. Are there packages for this situation?
thank you.
Here, I use TABstacks to make the data stacks, and the \scaleleftright[max-width]{left}{content}{right}
to add the brackets. Note that in the second matrix, I actually use a small negative "tabbedgap" of -1pt (i.e., column sep) to overlap the columns slightly. By comparison, I use a +1pt gap in the first matrix
\documentclass{article}
\usepackage{scalerel,tabstackengine,amssymb,amsmath}
\stackMath
\begin{document}
\[
\setstacktabbedgap{1pt}
A_h = \scaleleftright[1.5ex]{\langle}{\tabbedCenterstack{
&0&&0&\\
0&&0&&0\\
&0&&0&
}}{\rangle}
\text{, and }
\setstacktabbedgap{-1pt}
B_h =\scaleleftright[1.5ex]{\langle}{\tabbedCenterstack{
&-1&&-1&\\
-1&&6+\varepsilon^2&&-1\\
&-1&&-1&
}}{\rangle}
\]
\end{document}
While not shown here, uniform column width can be enforced by issuing \fixTABwidth{T}
prior to the stacks. In so doing, a change in the tabbedgap is correspondingly called for.
If one really hates typing double &&
, then this \active
alternative allows the use of #
to mean &&
, producing the same result:
\documentclass{article}
\usepackage{scalerel,tabstackengine,amssymb,amsmath}
\stackMath
\begin{document}
\[
\catcode`#=\active \def#{&&}
\setstacktabbedgap{1pt}
A_h = \scaleleftright[1.5ex]{\langle}{\tabbedCenterstack{
&0#0&\\
0#0#0\\
&0#0&
}}{\rangle}
\text{, and }
\setstacktabbedgap{-1pt}
B_h =\scaleleftright[1.5ex]{\langle}{\tabbedCenterstack{
&-1#-1&\\
-1#6+\varepsilon^2#-1\\
&-1#-1&
}}{\rangle}
\]
\end{document}
Three lines are covered by the standard \left<
and \right>
symbols.
Here's an hexagon
environment that can receive an optional argument for setting the width of the cells (default 1em):
\documentclass{article}
\usepackage{amsmath,collcell}
\newcolumntype{h}{>{\collectcell\hd}c<{\endcollectcell}}
\newcolumntype{k}[1]{@{\hspace{-#1\hexawidth}}}
\newcommand{\hd}[1]{\makebox[\hexawidth]{$#1$}}
\newlength{\hexawidth}
\newenvironment{hexagon}[1][1em]
{\setlength{\hexawidth}{#1}
\left<
\begin{array}{k{.33333}*{4}{hk{.5}}hk{.33333}}}
{\end{array}\right>}
\begin{document}
\[
A_{h}=
\begin{hexagon}
& 0 && 0 \\
0 && 0 && 0 \\
& 0 && 0 \\
\end{hexagon}
\qquad
B_{h}=
\begin{hexagon}[4em]
& -1 && -1 \\
-1 && 6+\varepsilon^2 && -1 \\
& -1 && -1 \\
\end{hexagon}
\]
\end{document}
Note that the \\
in the last row is necessary because of how collcell
works.
I didn't know scalerel
and \scaleleftright
command, so I've copied from Steven's answer. Thanks.
But I knew array
which can be also used for these expressions.
\documentclass{article}
\usepackage{scalerel,amsmath,array}
\usepackage{lmodern}
\begin{document}
\[
A_h = \scaleleftright[1.5ex]{\langle}{\begin{array}{@{}c@{}c@{}c@{}c@{}c@{}c@{}}
& 0 & & 0 & \\
0 & & 0 & & 0 \\
& 0 & & 0 &\\
\end{array}}{\rangle},
\text{and}\ B_h =
\scaleleftright[1.5ex]{\langle}{\begin{array}{@{}c@{}c@{}c@{}c@{}c@{}c@{}}
& -1 & & -1 & \\
-1 & & 6+\epsilon^2 & & -1 \\
& -1 & & -1 &\\
\end{array}}{\rangle}
\]
\end{document}
array
with a few empty cells between to me?