Graphics, Figures & Tablesdiagonal line in table (\backslashbox doesn't work fine)

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
wolfrain
Posts: 20
Joined: Wed Aug 25, 2010 2:42 am

diagonal line in table (\backslashbox doesn't work fine)

Post by wolfrain »

Hello there,

in the attachment I got a kindof table I want to generate in Latex file, but yet I cannot find a way to do it.

Basically I have tried this

Code: Select all

\begin{table}
\begin{center}
\begin{tabular}{r|cc}
\backslashbox{i}{j} & 1 & 2 \\\hline
1 & $1$ & $2$ \\
2 & $2$ & $1$ 
\end{tabular} 
\end{center} 
\caption{Prisoners' dilemma} 
\label{tab:prisoners}
\end{table}
and it turns out to be too big in the diagonal-lined box.
Table after compiled.
Table after compiled.
123.png (3.55 KiB) Viewed 25752 times

I want a smaller and compact one as the attachment shows.
This is something I want to make.
This is something I want to make.
Diagrams.png (720 Bytes) Viewed 25752 times
====================
One more problem occurs where the diagonal line disappears, although the reserved space is still there.
Table after compiled.
Table after compiled.
123.png (3.55 KiB) Viewed 25752 times
Am I missing any package without including it in the main file??

thank you,
wolfrain

Recommended reading 2024:

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

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

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

diagonal line in table (\backslashbox doesn't work fine)

Post by gmedina »

Hi,

you could use PGF/TikZ:

Code: Select all

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{matrix,calc}

\begin{document}

\begin{table}[!ht]
\centering
\begin{tikzpicture}
  \matrix (pridil) [%
    matrix of nodes,
    text width=4.1mm,text height=.3cm,
    text badly centered
  ]
  {%
    \null  & 1 & 2 \\
    1 & 1 & 2 \\
    2 & 1 & 2 \\
  };
  \draw[thin,black] (pridil-1-2.south west) -- (pridil-1-3.south east);
  \draw[thin,black] (pridil-2-1.north east) -- (pridil-3-1.south east);
  \draw[thin,black] (pridil-1-1.north west) -- (pridil-1-1.south east);
  \node at ($(pridil-1-1.north west)+(0.5,-0.1)$) {i};
  \node at ($(pridil-1-1.north west)+(0.1,-0.4)$) {j};
\end{tikzpicture}
\caption{Prisoners' dilemma} 
\label{tab:prisoners}
\end{table}

\end{document}
1,1,2,3,5,8,13,21,34,55,89,144,233,...
CrazyHorse
Posts: 351
Joined: Sat Aug 02, 2008 8:47 am

diagonal line in table (\backslashbox doesn't work fine)

Post by CrazyHorse »

wolfrain wrote:and it turns out to be too big in the diagonal-lined box.
123.png

I want a smaller and compact one as the attachment shows.
Diagrams.png

Code: Select all

\backslashbox[-10pt][l]{i}{j} & 1 & 2 \\\hline
use the optional arguments!

Herbert
wolfrain
Posts: 20
Joined: Wed Aug 25, 2010 2:42 am

diagonal line in table (\backslashbox doesn't work fine)

Post by wolfrain »

gmedina wrote:Hi,

you could use PGF/TikZ:

Code: Select all

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{matrix,calc}

\begin{document}

\begin{table}[!ht]
\centering
\begin{tikzpicture}
  \matrix (pridil) [%
    matrix of nodes,
    text width=4.1mm,text height=.3cm,
    text badly centered
  ]
  {%
    \null  & 1 & 2 \\
    1 & 1 & 2 \\
    2 & 1 & 2 \\
  };
  \draw[thin,black] (pridil-1-2.south west) -- (pridil-1-3.south east);
  \draw[thin,black] (pridil-2-1.north east) -- (pridil-3-1.south east);
  \draw[thin,black] (pridil-1-1.north west) -- (pridil-1-1.south east);
  \node at ($(pridil-1-1.north west)+(0.5,-0.1)$) {i};
  \node at ($(pridil-1-1.north west)+(0.1,-0.4)$) {j};
\end{tikzpicture}
\caption{Prisoners' dilemma} 
\label{tab:prisoners}
\end{table}

\end{document}
Thank you very much for your reply!

It works but unfortunately the end of diagonal line is not connected to the right-angle corner.
wolfrain
Posts: 20
Joined: Wed Aug 25, 2010 2:42 am

diagonal line in table (\backslashbox doesn't work fine)

Post by wolfrain »

CrazyHorse wrote:
wolfrain wrote:and it turns out to be too big in the diagonal-lined box.
123.png

I want a smaller and compact one as the attachment shows.
Diagrams.png

Code: Select all

\backslashbox[-10pt][l]{i}{j} & 1 & 2 \\\hline
use the optional arguments!

Herbert
Thank you!

Yea, it has become more compact, but still the diagonal line is missing... :(
CrazyHorse
Posts: 351
Joined: Sat Aug 02, 2008 8:47 am

diagonal line in table (\backslashbox doesn't work fine)

Post by CrazyHorse »

wolfrain wrote:
CrazyHorse wrote:
wolfrain wrote:and it turns out to be too big in the diagonal-lined box.
The attachment 123.png is no longer available

I want a smaller and compact one as the attachment shows.
The attachment Diagrams.png is no longer available

Code: Select all

\backslashbox[-10pt][l]{i}{j} & 1 & 2 \\\hline
use the optional arguments!
Yea, it has become more compact, but still the diagonal line is missing... :(
then make an _complete_ example, which shows this behaviour!

Code: Select all

\documentclass{article}
\usepackage{slashbox}

\begin{document}

\begin{tabular}{r|cc}
\backslashbox[10pt][l]{i}{j} & 1 & 2 \\\hline
1 & $1$ & $2$ \\
2 & $2$ & $1$
\end{tabular} 

\end{document}
this works!
Attachments
zz.png
zz.png (965 Bytes) Viewed 25736 times
wolfrain
Posts: 20
Joined: Wed Aug 25, 2010 2:42 am

Re: diagonal line in table (\backslashbox doesn't work fine)

Post by wolfrain »

It's weird... It doesn't appear in my case, although there is no error or warning but 1 Bad Box...
CrazyHorse
Posts: 351
Joined: Sat Aug 02, 2008 8:47 am

diagonal line in table (\backslashbox doesn't work fine)

Post by CrazyHorse »

wolfrain wrote:It's weird... It doesn't appear in my case, although there is no error or warning but 1 Bad Box...
did you view the dvi or pdf output?
And send the complete logfile of the example
Post Reply