6

As a pure challenge, I try to draw hugly top tabular column. I have almost done, still a poblem to control there height.

enter image description here

\documentclass[a4paper]{article}

\usepackage{array,tabularx,tikz,ragged2e,siunitx,xparse}
\usetikzlibrary{calc,backgrounds}

% 3 couches de dessin
\pgfdeclarelayer{background}
\pgfdeclarelayer{foreground}
\pgfsetlayers{background,main,foreground}

\renewcommand\tabularxcolumn[1]{m{#1}}

\makeatletter
\newcommand{\RowHeight}{% see e.g. https://tex.stackexchange.com/a/84536/121799
\def\tmp{\dimexpr\arraystretch\ht\strutbox+\arraystretch\ht\strutbox+\arraystretch\dp\@arstrutbox}\relax
\xdef\myrowheight{\the\tmp}\relax
}
\makeatother

\NewDocumentCommand{\Daube}{sms}{%
    \begin{tikzpicture}[baseline=(A.base),overlay]
        \node[text depth=0pt,text height=1ex,
            minimum height=\myrowheight,
            minimum width=2cm+2\tabcolsep]
            (A) {\textbf{\textsf{#2}}};
        \begin{pgfonlayer}{background}
        \draw[fill=blue!15,draw=white,line width=2\arrayrulewidth]
        \IfBooleanT{#1}{[rounded corners=12pt]}
            ([yshift=2.5\arrayrulewidth]A.south west)
         -- ([yshift=2\arrayrulewidth]A.north west)
        \IfBooleanT{#1}{[rounded corners=0pt]}
        \IfBooleanT{#3}{[rounded corners=12pt]}
        -- ([yshift=2\arrayrulewidth]A.north east)
        \IfBooleanT{#3}{[rounded corners=0pt]}
        -- ([yshift=2.5\arrayrulewidth]A.south east) -- cycle ;
        \end{pgfonlayer}
\end{tikzpicture}}

\begin{document}

{\renewcommand{\arraystretch}{1.3}
\begin{tabularx}{\linewidth}{%
    X*{3}{>{\Centering}m{2cm}}}
Entourer la ou les bonne(s) reponse(s)\RowHeight
& \Daube*{a}
& \Daube{b}
& \Daube{p}*
\\\hline
\end{tabularx}}

\bigskip

{\renewcommand{\arraystretch}{1.3}
\begin{tabularx}{\linewidth}{%
    X*{3}{>{\Centering}m{2cm}}}
Entourer la reponse\RowHeight
& \Daube*{a}
& \Daube{b}
& \Daube{p}*
\\\hline
\end{tabularx}}



\end{document}
  • 2
    Well, as I said in my previous answer, I had to put in by hand that there is a column that extends over two rows. That's why I put \arraystretch\ht\strutbox+\arraystretch\ht\strutbox instead of \arraystretch\ht\strutbox in the \RowHeight command. So that is the technical reason why things don't work out in your command, I think. Anyway, it will be interesting to see if someone can answer the question (+1). – user121799 Feb 13 '18 at 20:22
  • Is there a way to know how many lines are in the first table cell? If yes, you can put \dimexpr\arraystretch\ht\strutbox*<line number>+\arraystretch\dp\@arstrutbox ... – Jasper Habicht Feb 13 '18 at 20:37
  • @JasperHabicht Well, it's not that I haven't thought about this. But even if there is a way, you're not done, simply because some line could contain some large object such as $\displaystyle\int_a^b\dots$. – user121799 Feb 13 '18 at 20:41
  • @JasperHabicht Generally one or two lines of normal text to say how to tick the boxes, even empty. But the idea is to have a general \RowHeight that can be used in other places. – Tarass Feb 13 '18 at 20:45
  • Could you please check: I think your code does no longer compile after you have switched to \NewDocumentCommand. – user121799 Feb 13 '18 at 21:31
10

like this:?

enter image description here

edit: the code is combination of tabularx and tikz, as you desired :-). now is corrected on the way that are considered all improvements of solution in the addendum,

\documentclass[a4paper]{article}
\usepackage{tabularx}
\renewcommand\tabularxcolumn[1]{m{#1}}
\usepackage{ragged2e}
\usepackage{siunitx}
\usepackage{tikz}

\newcommand{\DL}[1]{%
\begin{tikzpicture}[baseline=(current bounding box.base)]
    \node[minimum width=\dimexpr2cm+2\tabcolsep,
          minimum height=12mm, text depth=0.25ex,
          inner ysep=2mm, outer sep=0pt,
       append after command={
             \pgfextra{\let\LN\tikzlastnode
        \path[draw=white, thick, fill=blue!15]
        (\LN.south west) -| (\LN.north east)
            {[rounded corners=6mm] -- (\LN.north west)} -- cycle;
       \path[draw=blue!15, thick, 
             shorten <=0.5\pgflinewidth, shorten >=0.5\pgflinewidth]       
        (\LN.south west) -- (\LN.south east);
                       }     },
        font=\bfseries] {#1};
\end{tikzpicture}   }
\newcommand{\DC}[1]{%
\begin{tikzpicture}[baseline=(current bounding box.base)]
    \node[minimum width=\dimexpr2cm+2\tabcolsep,
          minimum height=12mm, text depth=0.25ex,
          inner ysep=2mm, outer sep=0pt,
          append after command={
             \pgfextra{\let\LN\tikzlastnode
        \path[draw=white, thick, fill=blue!15]
        (\LN.south west) -| (\LN.north east) -| cycle;
       \path[draw=blue!15, thick, 
             shorten <=0.5\pgflinewidth, shorten >=0.5\pgflinewidth]
        (\LN.south west) -- (\LN.south east);
                      }     },
          font=\bfseries] {#1};
\end{tikzpicture}}
%
\newcommand{\DR}[1]{%
\begin{tikzpicture}[baseline=(current bounding box.base)]
    \node[minimum width=\dimexpr2cm+2\tabcolsep,
          minimum height=12mm, text depth=0.25ex,
          inner ysep=2mm, outer sep=0pt,
       append after command={
             \pgfextra{\let\LN\tikzlastnode
        \path[draw=white, thick, fill=blue!15]
        (\LN.south west) -- (\LN.south east)
            {[rounded corners=6mm] -- (\LN.north east)} -| cycle;
       \path[draw=blue!15, thick,
             shorten <=0.5\pgflinewidth, shorten >=0.5\pgflinewidth]
        (\LN.south west) -- (\LN.south east);
                       }     },
        font=\bfseries] {#1};
\end{tikzpicture}}

\begin{document}
    \begingroup
\renewcommand{\arraystretch}{1.3}
\begin{tabularx}{\linewidth}{%
    >{\raggedright}X *{3}{@{}>{\Centering}m{\dimexpr2cm+2\tabcolsep}@{}}
                            }
Entourer la ou les bonne(s) reponse(s)
    & \DL{a}    & \DC{b}    & \DR{p}    \\
    \hline
\end{tabularx}

\bigskip
\begin{tabularx}{\linewidth}{%
    >{\raggedright}X*{3}{@{}>{\Centering}m{\dimexpr2cm+2\tabcolsep}@{}}
                            }
Entourer la reponse
    & \DL{a}    & \DC{b}    & \DR{p}    \\
    \hline
\end{tabularx}
    \endgroup
\end{document}

if you like adopt tizz picture height to height of text in the first column, i don't know for automatic solution. however codes in command can be extend so that nodes height can be change in advance ad each its use (now is set to 12mm).

addedndum: meanwhile i made new solution which automatically adopt heights of tikz nodes to height of the first cell in the first table's column. calculation is based on measurement of the first cell content height. obtained result is:

enter image description here

mwe:

\documentclass[12pt]{article}
\usepackage{array,tabularx}
\renewcommand\tabularxcolumn[1]{m{#1}}
\usepackage{ragged2e}
\usepackage{siunitx}
\usepackage{tikz}
\usetikzlibrary{calc,backgrounds}

% commands \DaubeL, \DaubeL, \DaubeL are renamed for
% shorter writing to \DL, \DC and \DR
% all commands recoded (simplified) and adopted
% to automatic determination of tikz node heights
\newcommand{\DL}[2]{%
\begin{tikzpicture}[baseline=(current bounding box.base)]
    \node[minimum width=\dimexpr2cm+2\tabcolsep,
          minimum height=#1,  text depth=0.25ex,
          inner ysep=2mm, outer sep=0pt,
       append after command={
             \pgfextra{\let\LN\tikzlastnode
        \path[draw=white, thick, fill=blue!15]
        (\LN.south west) -| (\LN.north east)
            {[rounded corners=\CH/2] -- (\LN.north west)} -- cycle;
       \path[draw=blue!15, thick, shorten <=0.5\pgflinewidth]
        (\LN.south west) -- (\LN.south east);
                       }     },
        font=\bfseries] {#2};
\end{tikzpicture}   }
\newcommand{\DC}[2]{%
\begin{tikzpicture}[baseline=(current bounding box.base)]
    \node[minimum width=\dimexpr2cm+2\tabcolsep,
      minimum height=#1, text depth=0.25ex,
      inner ysep=2mm, outer sep=0pt,
          append after command={
             \pgfextra{\let\LN\tikzlastnode
        \path[draw=white, thick, fill=blue!15]
        (\LN.south west) -| (\LN.north east) -| cycle;
       \path[draw=blue!15, thick, shorten <=0.5\pgflinewidth]
        (\LN.south west) -- (\LN.south east);
                      }     },
          font=\bfseries] {#2};
\end{tikzpicture}}
%
\newcommand{\DR}[2]{%
\begin{tikzpicture}[baseline=(current bounding box.base)]
    \node[minimum width=\dimexpr2cm+2\tabcolsep,
          minimum height=#1, text depth=0.25ex,
          inner ysep=2mm, outer sep=0pt,
       append after command={
             \pgfextra{\let\LN\tikzlastnode
        \path[draw=white, thick, fill=blue!15]
        (\LN.south west) -- (\LN.south east)
            {[rounded corners=\CH/2] -- (\LN.north east)} -| cycle;
       \path[draw=blue!15, thick, 
                 shorten <=0.5\pgflinewidth, shorten >=0.5\pgflinewidth]
        (\LN.south west) -- (\LN.south east);
                       }     },
        font=\bfseries] {#2};
\end{tikzpicture}}

% command for calculation of height of first cel in the first column
% by experiments is determined minimum height: 1.7\baselineskip
\newcommand\firstcell[1]{
\sbox\cellbox{\parbox{\FC}{\raggedright #1}}
\pgfmathparse{max(8mm,\dimexpr\ht\cellbox+2\dp\cellbox)}
\setlength\CH{\pgfmathresult pt}
                        }
% boxes and length needed in automatic calculation
% of tikz nodes and for shortcut for first column width
\newsavebox\cellbox
\newlength{\CH}% CellHight
\newlength{\FC}% FirstColumn width
\begin{document}

\begingroup
\renewcommand{\arraystretch}{1.3}
\setlength\FC{\dimexpr\linewidth-6cm-6\tabcolsep\relax}
\firstcell{Entourer la ou les bonne(s) reponse(s)}
\begin{tabularx}{\linewidth}{%
    X*{3}{@{}>{\Centering}m{\dimexpr2cm+2\tabcolsep}@{}}
                            }
\usebox\cellbox
    & \DL{\CH}{a}   & \DC{\CH}{b}   & \DR{\CH}{p}    \\
    \hline
\end{tabularx}

\bigskip

\firstcell{Entourer la reponse}
\begin{tabularx}{\linewidth}{%
   X*{3}{@{}>{\Centering}m{\dimexpr2cm+2\tabcolsep}@{}}
                            }
\usebox\cellbox
    & \DL{\CH}{a}   & \DC{\CH}{b}   & \DR{\CH}{p}    \\
    \hline
\end{tabularx}
\endgroup
\end{document}

basic description of all changes of (heavily changed) of the first solution are described in mwe code.

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.