Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I'm using the package slashbox and my left column is reasonably wide, how can I tune the diagonal line (created by \backslashbox) such that it starts and ends in the corners of the cell?

Example code:

\documentclass[11pt]{article}
\usepackage{slashbox}
\usepackage{pict2e}
\begin{document}
 \begin{table}[ht!]
  \centering
  \begin{tabular}{ *{4}{|c}|} 
   \hline
   \backslashbox{foo}{bar} & test & header & header \\
   \hline
   relatively wide column& b & $3$ & $4$ \\
   ds & c & $1$ & $4$ \\
   \hline
  \end{tabular}
 \end{table}
\end{document}

Result:

alt text

share|improve this question
add comment

2 Answers

up vote 7 down vote accepted

The simplest and most straightforward way of doing this is to specify the literal size of the slashed box. In your case, it's about 40mm. So try this:

\backslashbox[40mm]{foo}{bar}

Generalising this approach would not be much more complicated. Compute the size of the backslashbox by taking the size of the column's widest string then add on two times the width of the table's column separators.

alt text

share|improve this answer
    
+1 for this simple solution. ALthough it increases the column with. I wasn't aware of that. –  Thorsten Donig Nov 13 '10 at 12:23
    
yes, nice answer to the question. Too bad there isn't a more automatic way to achieve this. Now I have a dilemma, @Thorsten answer offers a visually better way to solve this, but this answer by @Geoffrey is the exact answer to the question asked, which should I accept? –  Davy Landman Nov 13 '10 at 12:30
add comment

Since this is an issue concerning the slashbox package itself, the only solution might be a hack of the package source. Consider to restructure the table and tweak it with the booktabs package. See code below for some ideas.

\documentclass[11pt]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[font=small,labelfont=bf,tableposition=top]{caption}
\usepackage{booktabs,multirow}

\begin{document}
  \begin{table}[!ht]
    \caption{Table caption}\label{tab:default}
    \centering
    \begin{tabular}{*{4}{|c}|}\hline
      \multirow{2}{*}{foo} & \multicolumn{3}{|c|}{bar} \\ \cline{2-4}
       & test & header & header \\ \hline
      relatively wide column& b & $3$ & $4$ \\
      ds & c & $1$ & $4$ \\ \hline
    \end{tabular}
  \end{table}

  \begin{table}[!ht]
    \caption{Table caption}\label{tab:booktabs}
    \centering
    \begin{tabular}{*{4}{c}}\toprule
      \multirow{2}{*}[-0.5ex]{foo} & \multicolumn{3}{c}{bar} \\ \cmidrule{2-4}
       & test & header & header \\ \midrule
      relatively wide column& b & $3$ & $4$ \\
      ds & c & $1$ & $4$ \\ \bottomrule
    \end{tabular}
  \end{table}
\end{document}

It is also worth to think about dropping vertical lines to improve legibility of the tables as shown above.

share|improve this answer
    
yes, the actual table does not have vertical lines, but I included them to make the point about the diagonal line. and I was already using booktabs, but I just reduced the problem for the example, but I like the second suggestion, I hadn't thought about that. –  Davy Landman Nov 13 '10 at 12:02
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.