1

In a table created with tabularx of 6 columns and 7 rows (in the minimal example, I deleted some), I want to place figures created with tikz in the header.

These figures have already been defined and are used in another document. In order to be able to contain them in the header while being visible from the bottom of the class, I reduced them by a factor of 0.05.

By reducing this factor to 0.03, the problem disappears, but as a result the figures become too small to be visible from the back of the room.

In addition, I want to place the title of the header and the first column in the first cell at the top left separated by a diagonal.

I have tested the solutions to the following questions and none of them solve alignment problems.

entete-alignement

\documentclass[aspectratio=1610,10pt]{beamer} % Présentation générale et mise en page

\usepackage{tabularx}
\usepackage{tikz}           
\usepackage{slashbox,pict2e}

\usetheme{Warsaw}
\usefonttheme[onlymath]{serif}
\usecolortheme{dolphin}
\useoutertheme{infolines}       
\begin{document}

\def\tabularxcolumn#1{m{#1}}
\begin{frame}{Bilan}
\begin{tabularx}{7cm}{|c|*{2}{X|}}
\hline
\backslashbox{Unités}{Figures} %\rule[0pt]{0pt}{6mm} 
    & \centering\tikz[scale=.05]\draw[thick](0,0)--(6,6)--(0,12)--(0,18)--(6,12)--(12,12)--(18,18)--(18,12)--(12,6)--(18,0)--cycle;
    & \centering\tikz[scale=.05]\draw[thick](0,0)--(0,9)--(8,15)--(16,9)--(16,0)--cycle;
    \tabularnewline
\hline
$r_1$ \tikz[scale=.05]\draw(0,0)rectangle(6,3);&\rule[0mm]{0pt}{8mm} &  \tabularnewline
\hline
$t_1$ \tikz[scale=.05]\draw(0,0)--(3,3)--(6,0)--cycle;&\rule[0mm]{0pt}{8mm} &  \tabularnewline
\hline
\end{tabularx}

\end{frame}
\end{document}

How to make a correct diagonal line and center the figures correctly in the header without further reducing the size of the figures?

Translated with www.DeepL.com/Translator

  • The only space added by a tabular (or tabularx) is \arraystretch\ht\strutbox above the baseline and \arraystretch\dp\strutbox below the baseline. If the height and/or depth of a "box" is large enough, it will touch the top and/or bottom of the cell. If any box in the row exceeds these limits, they will be increased for the whole row. – John Kormylo Sep 22 '18 at 12:55
  • @JohnKormylo I didn't quite understand your solution to this problem. – AndréC Sep 22 '18 at 13:14
  • It wasn't a solution. Aslo, I forgot about the \tabcolsep on both sides. It seems that \backslashbox extends \tabcolsep beyond its measured width, so you can't just scale it up to match the height of the tikzfigure. – John Kormylo Sep 22 '18 at 13:21
3

The package \diagbox solves your problem, because has height control; the slash is calculated to contain the pair of texts and the content of the next cells must be less height than these. In this case using \diagbox[height=4em]{Unités}{Figures} the height of the first cell is greater than the contents of the drawings in tikz...

RESULT:

enter image description here

MWE:

% arara: pdflatex: {synctex: yes, action: nonstopmode}
\documentclass[aspectratio=1610,10pt]{beamer} % Présentation générale et mise en page
\usepackage{tabularx}
\usepackage{tikz}           
\usepackage{diagbox,pict2e} %Change to diagbox that controls the height of te first cell
\usetheme{Warsaw}
\usefonttheme[onlymath]{serif}
\usecolortheme{dolphin}
\useoutertheme{infolines}       
\begin{document}
    \def\tabularxcolumn#1{m{#1}}
    \begin{frame}{Bilan}
    \begin{table}[!h]
        \centering
        \begin{tabularx}{7cm}{|c|*{2}{X|}}\hline
            %Row1
            \diagbox[height=4em]{Unités}{Figures} %\rule[0pt]{0pt}{6mm} 
            &\centering\tikz[scale=.05]\draw[thick](0,0)--(6,6)--(0,12)--(0,18)--(6,12)--(12,12)--(18,18)--(18,12)--(12,6)--(18,0)--cycle;
            &\centering\tikz[scale=.05]\draw[thick](0,0)--(0,9)--(8,15)--(16,9)--(16,0)--cycle;
            \tabularnewline
            \hline
            %Row2
            $r_1$ \tikz[scale=.05]\draw(0,0)rectangle(6,3);&\rule[0mm]{0pt}{8mm} &  \tabularnewline
            \hline
            $t_1$ \tikz[scale=.05]\draw(0,0)--(3,3)--(6,0)--cycle;&\rule[0mm]{0pt}{8mm} &  \tabularnewline
            \hline
        \end{tabularx}
    \end{table}

    \end{frame}
\end{document}

ADDENDUM:

From the package documentation diagbox there are more controls for vertical position tuning, and as I see there is nothing for the vertical position adjustment, so I try with \vspace{} but it does not work, however the classic line break adjustment as suggested by @marmot, is a good option.

RESULT: enter image description here

MWE + marmot:

% arara: pdflatex: {synctex: yes, action: nonstopmode}
\documentclass[aspectratio=1610,10pt]{beamer} % Présentation générale et mise en page
\usepackage{tabularx}
\usepackage{tikz}           
\usepackage{diagbox,pict2e} %Change to diagbox that control the height of te first cell
\usetheme{Warsaw}
\usefonttheme[onlymath]{serif}
\usecolortheme{dolphin}
\useoutertheme{infolines}  
\usepackage{tikzmarmots}     
\begin{document}
    \def\tabularxcolumn#1{m{#1}}
    \begin{frame}{Bilan}
    \begin{table}[!h]
        \centering
        \begin{tabularx}{7cm}{|c|*{2}{X|}}\hline
            %Row1
            \diagbox[
                height=4em,
                innerwidth=6em,
                innerleftsep=0.5em,
                innerrightsep=0.5em
            ]{Unités\\[0.5em]}{\\[-0.5em]Figures} %\rule[0pt]{0pt}{6mm} 
            &\centering\tikz[scale=0.5]\marmot[teeth,whiskers];
            &\centering\tikz[scale=.05]\draw[thick](0,0)--(0,9)--(8,15)--(16,9)--(16,0)--cycle;
            \tabularnewline
            \hline
            %Row2
            $r_1$ \tikz[scale=.05]\draw(0,0)rectangle(6,3);&\rule[0mm]{0pt}{8mm} &  \tabularnewline
            \hline
            $t_1$ \tikz[scale=.05]\draw(0,0)--(3,3)--(6,0)--cycle;&\rule[0mm]{0pt}{8mm} &  \tabularnewline
            \hline
        \end{tabularx}
    \end{table}

    \end{frame}
\end{document}

RESULT:

  • +1 This is a clear progress, is it possible to shift the two texts in relation to the diagonal: Figures a little lower and Unités a little higher, i. e. to center them in a more aesthetic way? – AndréC Sep 22 '18 at 17:40
  • 1
    +1 @AndréC Yes, try e.g. \diagbox[height=4em]{Unités\\[1mm]}{\\[-3mm]Figures}. – marmot Sep 22 '18 at 19:15
  • @marmot It's better, but still too far from the diagonal. I've never seen this [1mm] before and I don't see it in the documentation of the \diagbox package; what is it? – AndréC Sep 22 '18 at 19:32
  • 1
    @AndréC Here we go then. Of course, you may want to read the question first to be able to fully appreciate the answer. – marmot Sep 22 '18 at 20:03
  • 1
    @AndréC, I added the suggestion of marmot's, and if it seems a good solution. I think that's the basic syntax of separation control of a parbox... – J Leon V. Sep 22 '18 at 20:16
2

The final problem was that the m{} column centers the contents offset by where it thinks the baseline should be, as does \backslashbox. When you scale \backslashbox, these compensations don't match.

This solution does not preserve the aspect ratio of \backslashbox, but is a lot simpler than adding \hspace{\tabcolsep} and @{} to both sides.

Removing the m{} column required adding this compensation to the \rule to center the next two rows.

\documentclass[aspectratio=1610,10pt]{beamer} % Présentation générale et mise en page

\usepackage{tabularx}
\usepackage{tikz}           
\usepackage{slashbox,pict2e}

\usetheme{Warsaw}
\usefonttheme[onlymath]{serif}
\usecolortheme{dolphin}
\useoutertheme{infolines}

\newlength{\offset}

\begin{document}

%\def\tabularxcolumn#1{m{#1}}
\begin{frame}{Bilan}
\sbox0{\raisebox{\dimexpr 0.5\depth-0.5\height}{\backslashbox{Unités}{Figures}}}% masuer width
\sbox1{\tikz[scale=.05,baseline=(current bounding box.center)]{\draw[thick](0,0)--(6,6)--(0,12)--(0,18)--(6,12)--(12,12)--(18,18)--(18,12)--(12,6)--(18,0)--cycle;}}% measure height (not quite .45cm)
\setlength{\offset}{\dimexpr 0.5\arraystretch\ht\strutbox-0.5\arraystretch\dp\strutbox}% offset from center to baseline
\begin{tabularx}{7cm}{|c|*{2}{X|}}
\hline
\resizebox{\wd0}{\ht1}{\usebox0}% scale to match height and not change width
    & \centering\usebox1
    & \centering\tikz[scale=.05,baseline=(current bounding box.center)]{\draw[thick](0,0)--(0,9)--(8,15)--(16,9)--(16,0)--cycle;}
    \tabularnewline
\hline
$r_1$  \tikz[scale=.05]{\draw(0,0)rectangle(6,3);} & \rule[\dimexpr \offset-4mm]{0pt}{8mm} & \\
\hline
$t_1$ \tikz[scale=.05]\draw(0,0)--(3,3)--(6,0)--cycle; & \rule[\dimexpr \offset-4mm]{0pt}{8mm} & \\
\hline
\end{tabularx}

\end{frame}
\end{document}

demo

  • +1Your answer interests me a lot and will help me progress with TeX (which is still difficult for a tikz user like me to access). Can you explain in more detail the different calculations you have made? – AndréC Sep 22 '18 at 15:48
  • 1
    Every box has a width, height (above baseline) and depth (below baseline). |raisebox for example doesn't actually raise the box, it just lowers the baseline. \raisebox also computes \height, \depth and \width for the contents. Usually I just put things in saveboxes and use \ht, \dp and \wd. To center a box, use \raisebox{0.5\depth-0.5\height}{...} \strutbox has the height of a capital letter and the depth of a descender (like g, y and p). \arraystretch is used to increase the space between rows of a tabular, but it doesn't exactly center them. – John Kormylo Sep 22 '18 at 18: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.