I'm searching how to have simultaneously :
- a proportional array definition (say, "this column represent 20% of the array width, the next is 30%" and so on) ;
- content centered both vertically and horizontally.
I've searched through StackExchange and ended with this code :
\documentclass[12pt, a4paper]{book}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{mathpazo}
\usepackage{tabularx}
\usepackage{geometry}
\usepackage[french]{babel}
\usepackage{tikz}
\geometry{top=1.5cm, bottom=1.5cm, left=1cm, right=1cm,
headheight=1cm, headsep=0.5cm,
footskip=1cm}
\begin{document}
Compléter le tableau suivant:
\renewcommand{\arraystretch}{3}
\renewcommand{\tabularxcolumn}[1]{m{#1}}
\newcolumntype{C}[1]{>{\hsize=#1\hsize\centering\arraybackslash}X}
\begin{tabularx}{\linewidth}{|C{.6}|C{1.4}|C{1.4}|C{.6}|}
%\begin{tabularx}{\linewidth}{|C{.15}|C{.35}|C{.35}|C{.15}|}
\hline
Inégalité & Phrase & Représentation graphique & Intervalle\\
\hline
$x<2$ & Bla & \fbox{\begin{tikzpicture}[scale=0.5, >=stealth]
% Repère
\def\xm{-4.9}
\def\xM{-\xm}
\draw[thick,->] (\xm,0) -- (\xM,0) ;
\foreach \x in {-4,...,4} {\node at (\x,0) {\tiny $|$} ; }
\node[below] at (0,0) {\footnotesize $0$} ;
\node[below] at (1,0) {\footnotesize $1$} ;
% Intervalle
\draw[line width=2.5pt] (-2,0) node {$]$} --(4,0) node {$]$} ;
\end{tikzpicture}} & $x\in\ldots$ \\
\hline
\end{tabularx}
\end{document}
Problems (see picture below) :
- the array width is too large, and I can't figure out why ;
- with redefining \arraystretch, the content is not anymore vertically centered ;
- the TikZ scheme is not vertically centered. If I embed it inside a new \parbox[c], I need to repeat horizontal centering instruction, which I find redundant and inelegant.
Additionnally, the tabularx declaration \begin{tabularx}{\linewidth}{|C{.15}|C{.35}|C{.35}|C{.15}|}
gives the same result, whereas it should'nt (if I understood right this answer, for example).
Thanks in advance for any tip or help.
Best Answer
With use of the
tabularray
package, table code is simple: