[Tex/LaTex] Tables in Latex with diagonal first row

tablestabularxtikz-pgf

I'm trying to create a table with a diagonal first row, like in how-to-draw-diagonal-table-borders-in-latex-like-in-excel

I've looked through the documentation for PGF-TiKZ, but am still unsure as to how to do the above.

From how-combine-make-diagonal-column-heads-in-table-with-multicolumn-headers I've managed to make diagonal entries on the top row, but what I would like is to add in the option of having it enclosed by cell borders like in excel, with an option to specify the length of each line of text within the top row. An option capability to close the top of the row with a border would be nice too. Is there any way to do this, preferably through the tabularx package?

Best Answer

This is a conceptual and kind of a manual solution. We first inject \tikzmarks into the column seperators and then use them to draw over the table which sits in a TikZ node.

\documentclass{article}
\usepackage{tikz,array}
\usetikzlibrary{calc}
\newcommand{\tikzmark}[1]{\tikz[remember picture,overlay]\coordinate (#1);}

\newcolumntype{T}[1]{@{\hspace{\tabcolsep}}c@{\hspace{\tabcolsep}\tikzmark{#1}}}

\begin{document}
\begin{tikzpicture}[remember picture]
\node[inner xsep=-\pgflinewidth,inner ysep=-\pgflinewidth] at (0,0) (mytable){%
\begin{tabular}{|T{a}|T{b}|c|}
\hline A&B&C\\
$\alpha$ & $\beta$ & $\theta$\\
foo &bar &Hello world \\\hline
\end{tabular}
};
\draw (mytable.north east) --++ (60:3cm);
\draw (mytable.north west) --++ (60:3cm);
\draw (mytable.north-|a) --++ (60:3cm);
\draw (mytable.north-|b) --++ (60:3cm);
\draw (mytable.north east) ++ (60:3cm) --([shift={(60:3cm)}]mytable.north west);

\node[rotate=60,anchor=west] at ($(mytable.north-|a)!0.5!(mytable.north west)$) {First Column};
\node[rotate=60,anchor=west] at ($(mytable.north-|a)!0.5!(mytable.north-|b)$) {Second Column};
\node[rotate=60,anchor=west] at ($(mytable.north-|b)!0.5!(mytable.north east)$) {Third Column};
\end{tikzpicture}
\end{document}

enter image description here

Related Question