TransWikia.com

Column headings on the table border

TeX - LaTeX Asked on November 30, 2020

I’m reproducing an old textbook but I can’t manage to typeset the tables.
The column headings, or the title of the table, should be placed on the border itself.

Here are a two examples:

example1

example2

The first one corresponds to the following code:

documentclass{standalone}

begin{document}
  fbox{
    begin{tabular}{llll|lll}
      & & SINGULIER & & & PLURIEL 
      & & & & & 
      & MASCULIN & FÉMININ & NEUTRE & MASCULIN & FÉMININ & NEUTRE 
      textsc{Nom.} & emph{is} & emph{ea} & emph{id} & emph{ei} ou emph{ii} & emph{eæ} & emph{ea}
    end{tabular}
  }
end{document}

I have neither included the accents nor the following lines as they are unrelated to the question.

2 Answers

Here is a solution with {NiceTabular} of nicematrix.

documentclass{article}
usepackage[french]{babel}
usepackage{lmodern}
usepackage{nicematrix}
usepackage{tikz}

begin{document}

newcolumntype{:}{!{vrule}}

begin{NiceTabular}{|llll:lll|}
Hline
noalign{vspace{4mm}}
  & MASCULIN & FÉMININ & NEUTRE & MASCULIN & FÉMININ & NEUTRE 
  textsc{Nom.} & emph{is} & emph{ea} & emph{id} & emph{ei} ou emph{ii} & emph{eæ} & emph{ea} 
noalign{vspace{1mm}}
Hline
CodeAfter
tikz 
draw (row-1-|col-1) -- node [fill=white] {SINGULIER} (row-1-|col-5) 
      (row-1-|col-5) -- node [fill=white] {PLURIEL} (row-1-|col-8) ;
end{NiceTabular}%

end{document}

You need several compilations (because nicematrix uses PGF/Tikz nodes).

Output of the above code

Correct answer by F. Pantigny on November 30, 2020

  • Typeset the table normally, including the headers.
  • Add tikznode commands for each header 'on the line'.
  • Wrap the whole tabular into a tikznode command.
  • Add a tikzpicture to draw the lines.

The tikznode command is defined and described in this answer to "How to add arrow in equations and matrix".

For fine-tuning, use the optional argument of tikznode to supply options to tikz. E.g., for adding more space around the tabular and the headers, you can define two styles by

tikzset{tab/.style={inner sep=2pt},hdr/.style={inner xsep=4pt}}

and add tab and hdr as options to the tikznode commands.

enter image description here

documentclass[border=5pt]{standalone}
usepackage{tikz}
newcommandtikznode[3][]{%
  tikz[remember picture,baseline=(#2.base)]
    node[minimum size=0pt,inner sep=0pt,#1](#2){#3};%
}
tikzset{tab/.style={inner sep=2pt},hdr/.style={inner xsep=4pt}}
begin{document}
tikznode[tab]{singplu}{%
  begin{tabular}{llll|lll}
    multicolumn{4}{c}{tikznode[hdr]{sing}{SINGULIER}} &  multicolumn{3}{c}{tikznode[hdr]{plu}{PLURIEL}} 
    & & & & & 
    & MASCULIN & FÉMININ & NEUTRE & MASCULIN & FÉMININ & NEUTRE 
    textsc{Nom.} & emph{is} & emph{ea} & emph{id} & emph{ei} ou emph{ii} & emph{eæ} & emph{ea}
  end{tabular}%
}%
begin{tikzpicture}[remember picture,overlay]
  draw (singplu.south west) |- (sing);
  draw (sing) -- (plu);
  draw (plu) -| (singplu.south east);
  draw (singplu.south east) -- (singplu.south west);
end{tikzpicture}

end{document}

Answered by gernot on November 30, 2020

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP