Graphics, Figures & TablesHow to improve diagbox spacing and automate diagonal placement?

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
user49915
Posts: 81
Joined: Wed Apr 17, 2019 12:51 pm

How to improve diagbox spacing and automate diagonal placement?

Post by user49915 »

Feeding the input

Code: Select all

\documentclass{article}
\pagestyle{empty}
\usepackage{diagbox}
\DeclareRobustCommand*{\concreteState}[1]{\ifmmode\mathsf{#1}\else\textsf{#1}\fi}
\begin{document}%
\newcommand{\RestOfContents}{  & \concreteState{green} & \concreteState{red}\\
	\hline
	\concreteState{green} & (\concreteState{g},\concreteState{g})  & (\concreteState{g},\concreteState{r})\\
	\concreteState{yellow} & (\concreteState{ng},\concreteState{g}) & (\concreteState{ng},\concreteState{r})\\
	\concreteState{red}  & (\concreteState{ng},\concreteState{g}) & (\concreteState{ng},\concreteState{r})\\
	\concreteState{yellowgreen} & (\concreteState{ng},\concreteState{g}) & (\concreteState{ng},\concreteState{r})
}%
\noindent%
Fallback:%%% This is ugly an not necessarily understandable.
\[
\begin{array}{l|cc}
  a\ \backslash\ b%%% That's what we do without diagbox.
  \RestOfContents
\end{array}%
\]
Good usage of horizontal space, but the diagonal is not actually a diagonal, and vertical space is wasted:
\begin{center}%
\begin{tabular}{l|cc}
	\diagbox{\(a\)}{\(b\)}%%% That's what I'd like to type in and leave the rest to the macros!
  \RestOfContents
\end{tabular}%
\end{center}
The diagonal is actually a diagonal, but both horizontal and vertical space is wasted:
\begin{center}%
\begin{tabular}{l|cc}
	\diagbox{\quad\(a\)\quad}{\quad\(b\)\quad}
  \RestOfContents
\end{tabular}%
\end{center}
\end{document}
to pdflatex results in
mwe.png
mwe.png (193.09 KiB) Viewed 2817 times
Is there any way to turn the purported diagonal to an actual diagonal and NOT waste horizontal and vertical space? Ideas are welcome.

Recommended reading 2024:

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

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

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

Post Reply