shares
 

A quick visual guide to creating table cells with diagonal lines in LaTeX

By Lian Tze Lim

There are many packages in LaTeX that help with table creation – booktabs is a popular example – and there are also a growing number of automatic table generators now available online (such as this one) which are a great way to create the LaTeX code for a table without having to type it out manually. There's even a package to help you create really long tables that span multiple pages! But what if you want to add some additional styling or formatting to certain cells within your tables?

The simple answer is that there's usually a package for it! Here we focus on one particular piece of cell formatting – how to create table cells with diagonal lines.

These diagonal lines often used in the upper left corner of a table to allow both row and column headers to be placed in that same cell, and there are two similar packages that can be used to achieve this: slashbox and diagbox.

To help you try this out, I've added a short example which demonstrates how to produce diagonal lines in table cells using those packages. I personally prefer to use diagbox as I find that the lines produced by slashbox can be more jagged, while the diagbox lines are smoother, but I've included options for both in the example so you can decide for yourself!

I also used this as an excuse to try out LICEcap to record a gif of how to add the slashbox.sty file to your project directly from the CTANrepository. I hope you like it :)

Using the slashbox and diagbox LaTeX packages for tables on Overleaf(click the gif to view a bigger version)

I hope this helps, and if you'd like to see more animated gif tutorials please let us know!

Lian Tze Lim

Lian Tze Lim

Community TeXpert

Computer scientist, lecturer, trainer. Enjoys tinkering with LaTeX in the name of productive procrastination (ahem). Personal motto: "all research students are insane at one time or another".