Graphics, Figures & Tablesmulti-element framebox in array

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
Sagil
Posts: 20
Joined: Tue Mar 24, 2009 1:15 am

multi-element framebox in array

Post by Sagil »

My problem is the following: I have an array, and want to put frame boxes around elements. For a single element that's simple, e.g.

Code: Select all

\begin{array}{ccc}
0 & \fbox{1} & 1 \\
1 & 0 & 0
\end{array}
But how can you do this for multiple elements? E.g. put a box around the two adjacent '1's?

Thanks, Henning

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

User avatar
gmedina
Posts: 2313
Joined: Wed Jul 11, 2007 11:45 pm

multi-element framebox in array

Post by gmedina »

Hi Henning,

the hhline package could be helpful; take a look at the following example:

Code: Select all

\documentclass{article}
\usepackage{hhline}

\begin{document}

\[
  \begin{array}{ccc}
    \hhline{~--}0 & \multicolumn{1}{|c}{1} & \multicolumn{1}{c|}{1} \\
    \hhline{~--}1 &  0 & 0
  \end{array}
\]

\end{document}
Edit: the same result can be achieved without extra packages:

Code: Select all

\documentclass{article}

\begin{document}

\[
  \begin{array}{ccc}
    \cline{2-3}
    0 & \multicolumn{1}{|c}{1} & \multicolumn{1}{c|}{1} \\\cline{2-3}
    1 &  0 & 0
  \end{array}
\]

\end{document}
1,1,2,3,5,8,13,21,34,55,89,144,233,...
Sagil
Posts: 20
Joined: Tue Mar 24, 2009 1:15 am

multi-element framebox in array

Post by Sagil »

Thanks, that's close but it doesn't look quite right - basically I want elements to appear as "grouped together". Consider e.g. the following code:

Code: Select all

\documentclass{article}
\usepackage{hhline}
\begin{document}
\newcommand{\lone}{\multicolumn{1}{|c}{1}}
\newcommand{\rone}{\multicolumn{1}{c|}{1}}
\newcommand{\lrone}{\multicolumn{1}{|c|}{1}}
\[
\left(
\begin{array}{cccccc}
\hhline{~~-~--}
0 & 0 & \lrone & 0 & \lone & \rone\\
\hhline{-~----}
\lrone & 0 & 0 & \lrone & 0 & \lrone\\
\hhline{-~----}
0 & 0 & \lrone & 0 & \lrone & 0\\
\hhline{~--~--}
0 & \lrone & 0 & 0 & 0 & \lrone\\
\hhline{~-~~~-}
\end{array}
\right)
\]
\[
\left(
\begin{array}{cccccc}
\hhline{~~~~--}
0 & 0 & \fbox{1} & 0 & \lone & \rone\\
\hhline{~~~~--}
\fbox{1} & 0 & 0 & \fbox{1} & 0 & \fbox{1}\\
0 & 0 & \fbox{1} & 0 & \fbox{1} & 0\\
0 & \fbox{1} & 0 & 0 & 0 & \fbox{1}\\
\end{array}
\right)
\]
\end{document}
This generates the following two matrices as output:
fboxmatrix.png
fboxmatrix.png (4.75 KiB) Viewed 4107 times
In the first one groupings are not very clear when '1's are close together, in the second one the box alignment is off. Any ideas?
Post Reply