0

I am trying to recreate the last table on page 4 of this document, and it should look something like this:

enter image description here

Here is what I have so far:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{array}
\usepackage{multirow}

\begin{document}

\setlength{\extrarowheight}{20pt}
\begin{center}
\begin{tabular}{|c|c|c|c|}
\hline
\multicolumn{2}{| c }{Xenomai tasks} & \multicolumn{2}{ | c |}{Linux threads/processes} \\
\hline
\multicolumn{2}{| c }{Xenomai services} & \multicolumn{2}{ | c |}{Linux services} \\
\hline
\multirow{2}{*}{Real-time device driver} & Xenomai kernel & OS kernel & \multirow{2}{*}{Device driver}  \\
\cline{2-3}
& \multicolumn{2}{c|}{Hardware Abstraction Layer (HAL)} & \\
\hline
\multicolumn{4}{| c |}{Adeos interrupt pipeline} \\
\hline
Specific hardware processes & \multicolumn{2}{ c |}{CPU + motherboard} & Specific hardware processes  \\
\hline
\end{tabular}
\end{center}

\end{document}

As it is right now, only multirow cells are aligned vertically and horizontally in the middle. But for multicolumns such as the first one that has the text Xenomai tasks I cannot get the text to be centered vertically.

I tried different solutions from other posts, but I haven't been able to make it work.

For example, I tried the following:

\begin{tabular}{|m{10em}|c|c|m{10em}|}

Is there a simple way to align the text in all cells to be in the middle?

1

Your table cells are not vertically centered because \extrarowheight seems to be added at the top of the rows. To compensate that, you can either use \\[...pt] instead ot \\ or go for the cellspace package:

enter image description here

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{array}
\usepackage{multirow}

\usepackage{cellspace}
\setlength\cellspacetoplimit{10pt}
\setlength\cellspacebottomlimit{10pt}


\begin{document}

\begin{center}
\setlength\extrarowheight{5pt}
\begin{tabular}{|c|c|c|c|}
\hline
\multicolumn{2}{| c }{Xenomai tasks} & \multicolumn{2}{ | c |}{Linux threads/processes} \\[5pt]
\hline
\multicolumn{2}{| c }{Xenomai services} & \multicolumn{2}{ | c |}{Linux services} \\[5pt]
\hline
\multirow{3}{*}{Real-time device driver} & Xenomai kernel & OS kernel & \multirow{3}{*}{Device driver}  \\[5pt]
\cline{2-3}
& \multicolumn{2}{c|}{Hardware Abstraction Layer (HAL)} & \\[5pt]
\hline
\multicolumn{4}{| c |}{Adeos interrupt pipeline} \\[5pt]
\hline
Specific hardware processes & \multicolumn{2}{ c |}{CPU + motherboard} & Specific hardware processes  \\[5pt]
\hline
\end{tabular}
\end{center}

\bigskip

\begin{center}
\begin{tabular}{|Sc|Sc|Sc|Sc|}
\hline
\multicolumn{2}{| Sc }{Xenomai tasks} & \multicolumn{2}{ | Sc |}{Linux threads/processes} \\
\hline
\multicolumn{2}{| Sc }{Xenomai services} & \multicolumn{2}{ | Sc |}{Linux services} \\
\hline
\multirow{3.5}{*}{Real-time device driver} & Xenomai kernel & OS kernel & \multirow{3.5}{*}{Device driver}  \\
\cline{2-3}
& \multicolumn{2}{Sc|}{Hardware Abstraction Layer (HAL)} & \\
\hline
\multicolumn{4}{| Sc |}{Adeos interrupt pipeline} \\
\hline
Specific hardware processes & \multicolumn{2}{ Sc |}{CPU + motherboard} & Specific hardware processes  \\
\hline
\end{tabular}
\end{center}

\end{document}

Please keep in mind that your table is too wide for the textwidth of a standard article document. In order to change that you might want to introduce linebreaks in the cells.

  • Thank you, this is a fantastic answer. And yes, you are right about the table width. I have changed this to fit the article document. – David Jul 13 at 14:16
1

Since you have full control per cell in a calstable, the package cals is well suited for such type of tabulars. To centre text vertically in a cell, you just issue the commands \vfil inside the cell.

Here is an MWE for the tabular in question:

\documentclass{article}
\usepackage{cals, caption, xcolor}

\let\nc=\nullcell                    % CALS Shortcuts
\let\sc=\spancontent
\begin{document}

\small
\begin{calstable}[c]  % Left aligned CALS tabular

% Calculate the column width
\colwidths{{\dimexpr(\columnwidth)/88*13\relax}
            {\dimexpr(\columnwidth)/88*2\relax}
            {\dimexpr(\columnwidth)/88*18\relax}
            {\dimexpr(\columnwidth)/88*18\relax}
            {\dimexpr(\columnwidth)/88*2\relax} 
            {\dimexpr(\columnwidth)/88*13\relax}
            {\dimexpr(\columnwidth)/88*14\relax}
    }

% The tabular fills the text area if sum of all columns is 88

% Set up the tabular
\makeatletter
\def\cals@framers@width{0.4pt}   % Outside frame rules
\def\cals@framecs@width{0,4pt}
\def\cals@bodyrs@width{0.4pt}  % Rule between header and tabular body
\def\cals@cs@width{0.4pt}             % Inside vertical rules
\def\cals@rs@width{0.4pt}              % Inside horizontal rules
\def\cals@bgcolor{}

\def\bb{\ifx\cals@borderB\relax     % Bottom border switch (off-on)
    \def\cals@borderB{0pt}
\else \let\cals@borderB\relax\fi}

\def\tb{\ifx\cals@borderT\relax     % Top border switch (off-on)
    \def\cals@borderT{0pt}
\else \let\cals@borderT\relax\fi}

\def\lb{\ifx\cals@borderL\relax     % Left border switch (off-on)
    \def\cals@borderL{0pt}
\else \let\cals@borderL\relax\fi}

\def\rb{\ifx\cals@borderR\relax     % Right border switch (off-on)
    \def\cals@borderR{0pt}
\else \let\cals@borderR\relax\fi}

\def\green{\ifx\cals@bgcolor\empty     % "Switch" to turn on and off colour
    \def\cals@bgcolor{green!80}
\else \def\cals@bgcolor{} \fi}

\def\lgreen{\ifx\cals@bgcolor\empty     % "Switch" to turn on and off colour
    \def\cals@bgcolor{green!15}
\else \def\cals@bgcolor{} \fi}

\def\dgreen{\ifx\cals@bgcolor\empty     % "Switch" to turn on and off colour
    \def\cals@bgcolor{green!80!black}
\else \def\cals@bgcolor{} \fi}


\def\red{\ifx\cals@bgcolor\empty     % "Switch" to turn on and off colour
    \def\cals@bgcolor{red!80}
\else \def\cals@bgcolor{} \fi}

\def\orange{\ifx\cals@bgcolor\empty     % "Switch" to turn on and off colour
    \def\cals@bgcolor{orange!80}
\else \def\cals@bgcolor{} \fi}

\def\lorange{\ifx\cals@bgcolor\empty     % "Switch" to turn on and off colour
    \def\cals@bgcolor{orange!30}
\else \def\cals@bgcolor{} \fi}

\def\yellow{\ifx\cals@bgcolor\empty     % "Switch" to turn on and off colour
    \def\cals@bgcolor{yellow!80}
\else \def\cals@bgcolor{} \fi}

\def\plum{\ifx\cals@bgcolor\empty     % "Switch" to turn on and off colour
    \def\cals@bgcolor{blue!30!red!30}
\else \def\cals@bgcolor{} \fi}

\def\violet{\ifx\cals@bgcolor\empty     % "Switch" to turn on and off colour
    \def\cals@bgcolor{violet!80}
\else \def\cals@bgcolor{} \fi}


% R1H1
\brow
    \green\nc{ltb}
    \nc{tb}
    \nc{rtb}\alignC\sc{\vfil Xenomai tasks}
    \lb\nc{ltb}
    \nc{tb}
    \nc{rtb}\alignC\sc{\vfil Linux threads/processes}\lb\green
    \tb\rb\alignL\cell{\vfil user mode}\tb\rb
\erow
%R3B2
\brow
    \red\nc{ltb}
    \nc{tb}
    \nc{rtb}\alignC\sc{\vfil Xenomai services}\red
    \orange\nc{ltb}
    \nc{tb}
    \nc{rtb}\alignC\sc{\vfil Linux services}\orange
    \tb\rb\alignL\cell{\vfil kernel mode}\tb\rb
\erow
%R4B3
\brow
    \lgreen\nc{lrt}
    \lb\cell{}\lb\lgreen
    \yellow\alignC\cell{\vfil Xenomai kernel}
    \alignC\cell{\vfil OS kernel}\yellow
    \lgreen\rb\cell{}\rb
    \nc{lrt}\lgreen
    \tb\rb\nc{lrt}\tb\rb
\erow
%R5B4
\brow
    \lgreen\nc{lrb}\alignL\sc{\vfil real-time\\devic\\driver}\lgreen
    \lorange\nc{ltb}
    \nc{tb}
    \nc{tb}
    \nc{rtb}\alignC\sc{\vfil Hardware Abstraction Layer (HAL)}\lorange
    \lgreen\nc{lrb}\alignR\sc{\vfil device driver}\lgreen
    \tb\rb\alignL\nc{lrb}\sc{\vfil software}\tb\rb
\erow
%R6B5
\brow
    \dgreen\nc{ltb}
    \nc{tb}
    \nc{tb}
    \nc{tb}
    \nc{tb}
    \nc{rtb}\alignC\sc{\vfil Adeos (interrupt pipeline)}\dgreen
    \tb\rb\alignL\cell{}\tb\rb
\erow
%R7B6
\brow
    \plum\nc{ltb}
    \nc{rtb}\alignC\sc{\vfil specific hardware processes}\plum
    \violet\nc{ltb}
    \nc{rtb}\alignC\sc{\vfil CPU + motherboard}\violet
    \plum\nc{ltb}
    \nc{rtb}\alignC\sc{\vfil specific hardware processes}\plum
    \bb\tb\rb\alignL\cell{\vfil hardware}\tb\rb\bb
\erow
\makeatletter
\end{calstable}\par
\end{document}

enter image description here

  • Thank you! I didn't know about calstable. I will check it out – David Jul 17 at 15:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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