3

I want to create a table like this in LaTeX:

This is how it should look like

How would I do that?

egreg
  • 1,121,712
Johann Bauer
  • 251
  • 3
  • 8
  • 1
    Please provide an MWE. Like this, you are leaving all the work to the community. Will this be an equation or a table in between text or a figure (like TikZ)? – LaRiFaRi Mar 20 '15 at 11:35
  • 1
    Here you'll find more info on how to create tables with LaTeX, including the answers to many common problems and FAQs: http://en.wikibooks.org/wiki/LaTeX/Tables i – MostlyHarmless Mar 20 '15 at 11:43
  • 1
    @jreuab Check this very similar question on simplex with an alternate format for the simplex tableau http://tex.stackexchange.com/questions/89299/how-to-draw-the-following-table-simplex-tableau – R. Schumacher Mar 20 '15 at 14:47

3 Answers3

8

Just a bit of patience in removing the unwanted rules. The gap for getting the fraction not to touch the rule is obtained by an invisible rule (I'd use the slashed form, by the way).

\documentclass{article}

\begin{document}
\[
\begin{array}{l|c|rr|c|c|}
\multicolumn{2}{c}{} & % omit the vertical lines
\multicolumn{1}{c}{x_1} &
\multicolumn{1}{c}{\mbox{\boldmath$x_6$}} &
\multicolumn{2}{c}{} \\
\cline{2-5}
 & -1 & 1 & 3 & 0 & \multicolumn{1}{c}{} \\
\cline{2-6}
\mbox{\boldmath$x_1$}
 & 1 & 7 & 2 & 5 & \rule{0pt}{1.2\ht\strutbox}\frac{5}{2} \\[1ex]
x_2
 & 0 & 1 & -6 & 9 & - \\[1ex]
x_3
 & 2 & -10 & 4 & 20 & 5 \\[1ex]
x_4
 & 3 & -1 & 0 & 8 & - \\
\cline{2-6}
\multicolumn{2}{c|}{}
 & -17 & 13 & 69 & \multicolumn{1}{c}{} \\
\cline{3-5}
\end{array}
\]
\end{document}

enter image description here

egreg
  • 1,121,712
  • 1
    a niggle: the digits in the cells at the top and bottom look relatively too close to the rule above them. the adjustment made for the fraction would be salutary there as well. – barbara beeton Mar 20 '15 at 15:36
7

A solution with blkarray:

% arara: pdflatex

\documentclass{article}
\usepackage{blkarray}
\usepackage{bm}

\begin{document}
\[
\renewcommand{\arraystretch}{1.1}
\begin{blockarray}{l*{5}{r}} % for your image, you will have to change column 2, 5, and 6 to `c` in all blocks. 
    & & x_5&\boldsymbol{x_6}&\\\cline{2-5}
    \begin{block}{l|r|rr|r|r}
        \null& -1 & 1 & -3 & 0 &\\
    \end{block}\cline{2-6}
    \begin{block}{l|r|rr|r|r|}
        \boldsymbol{x_1} & 1 & 7 & 2 & 5 & \frac{5}{2}\\
        x_2 & 0 & 1 & -6 & 9 & -\\
        x_3 & 2 & -10 & 4 & 20 & 5\\
        x_4 & 3 & -1 & 0 & 8 & -\\  
    \end{block}\cline{2-6}
    \begin{block}{lr|rr|r|r}
        \null& \null & -17 & 13 & 69 &\\
    \end{block}\cline{3-5}
\end{blockarray}
\]
\end{document}

enter image description here

LaRiFaRi
  • 43,807
6

With a tabular

\documentclass{article}

\usepackage{array,bm}

\newcolumntype{R}{>{$}r<{$}}
\newcolumntype{C}{>{$}c<{$}}
\renewcommand{\arraystretch}{1.2}


\begin{document}
\begin{tabular}{C|C|RR|C|C|}
  \multicolumn{2}{c}{} & x_5 & \multicolumn{1}{r}{$\bm{x_6}$} \\
  \cline{2-5}
   & -1 & 1 & -3 & 0 \\
  \cline{2-6}
  \bm{x_1} & 1 & 7 & 2 & 5 & \frac{5}{2} \\ 
  x_2 & 0 & 1 & -6 & 9 & - \\
  x_3 & 2 & -10 & 4 & 20 & 5 \\
  x_4 & 3 & -1 & 0 & 8 & - \\
  \cline{2-6}
  \multicolumn{2}{c|}{} & -17 & 13 & 69 \\
  \cline{3-5}
\end{tabular}
\end{document} 

enter image description here

karlkoeller
  • 124,410