2

I would like to know what is forcing a middle vertical alignment in the following example in the main table. The inner tables are OK but the outer table does not respect the different alignments, which are defined in the line colspec = {Q[l,t] Q[r,b]}.

Thanks

\documentclass{article}
\usepackage{tikz}
\usepackage{tabularray}

\NewDocumentEnvironment{mathtask}{+b}{%
    \begin{tblr}{
        colspec={Q[r,b,1cm] Q[c,b,1cm] Q[l,mode=math,1cm]},
        vlines,hlines,
    }
    #1
\end{tblr}}{}


\begin{document}

\centering%
\begin{tblr}{
        vlines, hlines,
        columns = {0.5\textwidth-13pt, colsep=6pt},
        rows    = {4cm, rowsep=2pt},
        colspec = {Q[l,t] Q[r,b]},
    }
    \begin{mathtask}
        {aaa\\bbb\\ccc\\ddd} & {xx\\yy} & c
    \end{mathtask}
    &
    \begin{mathtask}
        {aaa\\bbb} & xxxx & d
    \end{mathtask}
    \\
    \begin{mathtask}
        {aaa\\bbb\\ccc\\ddd\\eee\\ff} & {xx\\yy} & e
    \end{mathtask}
    &
    \begin{mathtask}
        {aaa\\bbb\\ccc} & {xx\\yy} & f
    \end{mathtask}
\end{tblr}

\end{document}

enter image description here


EDIT. The original problem.

\documentclass{article}
\usepackage{mathtools}
\usepackage{tikz}
\usepackage{tabularray}
\usepackage[showframe]{geometry}

\newlength{\cwidth}  \setlength{\cwidth}{0.49\textwidth}
\newlength{\cheight} \setlength{\cheight}{0.49\textheight}

\newcommand\tasknumber[1]{%
    \begin{tikzpicture}[
            inner sep=0pt,outer sep=0pt, minimum size=21pt,
            baseline={([yshift=-3pt]current bounding box.center)},
        ]
        \node [draw,circle,color=white,fill=white!45!black,] {#1};
    \end{tikzpicture}}
\setlength{\tabcolsep}{3pt}

\NewDocumentEnvironment{mathtask}{+b}{%
    \begin{tblr}{
        colspec={l l l},
        column{2}={font=\bfseries},
        column{3}={mode=math},
        columns={colsep=3pt},
    }
    #1
    \end{tblr}
}{}

\pagestyle{empty}



\begin{document}

\centering
\begin{tblr}{
        colspec={l l},
        columns={\cwidth-3pt, colsep=3pt},
        rows={\cheight, rowsep=3pt},
        vline{2} = solid,
        hline{2} = solid,
    }
    \begin{mathtask}
        \tasknumber{1} &
        Solve the system: &
        \begin{cases}
            x + y + = 1 \\
            x + y + = 1 \\
            x + y + = 1 \\
            x + y + = 1 \\
            x + y + z = 2
        \end{cases}
    \end{mathtask}
    &
    \begin{mathtask}
        \tasknumber{2} &
        Solve the system: &
        \begin{cases}
            x + y + = 1 \\
            x + y + = 3 \\
            x + y + z = 2
        \end{cases}
    \end{mathtask}
    \\
    \begin{mathtask}
        \tasknumber{3} &
        Solve the equation: &
        x + y + z = 2
    \end{mathtask}
    &
    \begin{mathtask}
        \tasknumber{50} &
        Solve the system: &
        \begin{cases}
            x + y + = 1 \\
            x + y + z = 2
        \end{cases}
    \end{mathtask}
\end{tblr}

\end{document}
1
  • 1
    It always seems to do that, even with text as cell contents. I looked in the code, and it looks like it always uses m as valign, even if you specify something else. Maybe it is a bug. Apr 29, 2022 at 21:14

1 Answer 1

5

When each cell has only a single line of text in a row, the vertical alignment options t/m/b are the same for this row. This is true also for traditional tabular environment (except that there is still an aligmment bug in tabular environment).

Although mathtask environment consists of a complicated table, TeX still treats it as a box, so those cells are of single line (you can see it more clearly by adding some text before and after mathtask environment). Therefore in outer table for example colspec={Q[t]Q[b]} and colspec={Q[b]Q[m]} and colspec={Q[m]Q[t]} will produce the same result.

I am not sure what you really want from your code. But you could change the alignment of the inner tables:

\documentclass{article}

\usepackage{tabularray}
\NewDocumentEnvironment{mathtask}{O{}+b}{%
    \begin{tblr}[T]{
        colspec={Q[r,#1,1cm] Q[c,#1,1cm] Q[l,mode=math,1cm]},
        vlines,hlines,
    }
    #2
\end{tblr}}{}

\begin{document}

\centering
\begin{tblr}{
        vlines, hlines,
        columns = {0.5\textwidth-13pt, colsep=6pt},
        rows    = {4cm, rowsep=2pt},
        colspec = {Q[l,t] Q[r,b]},
    }
    a\begin{mathtask}[t]
        {aaa\\bbb\\ccc\\ddd} & {xx\\yy} & c
    \end{mathtask}b
    &
    a\begin{mathtask}[t]
        {aaa\\bbb} & xxxx & d
    \end{mathtask}b
    \\
    a\begin{mathtask}[b]
        {aaa\\bbb\\ccc\\ddd\\eee\\ff} & {xx\\yy} & e
    \end{mathtask}b
    &
    a\begin{mathtask}[b]
        {aaa\\bbb\\ccc} & {xx\\yy} & f
    \end{mathtask}b
\end{tblr}

\end{document}

enter image description here


EDIT: For your original problem, you need to move \tasknumber out of mathtask and set vertical alignment h for these new columns:

\documentclass{article}
\usepackage{mathtools}
\usepackage{tikz}
\usepackage{tabularray}
\usepackage[showframe]{geometry}

\newlength{\cheight} \setlength{\cheight}{0.5\textheight-6.02pt}

\newcommand\tasknumber[1]{%
    \begin{tikzpicture}[
            inner sep=0pt,outer sep=0pt, minimum size=21pt,
            baseline={([yshift=-3pt]current bounding box.center)},
        ]
        \node [draw,circle,color=white,fill=white!45!black,] {#1};
    \end{tikzpicture}}
\setlength{\tabcolsep}{3pt}

\NewDocumentEnvironment{mathtask}{+b}{%
    \begin{tblr}{
        colspec={ll},
        column{1}={font=\bfseries},
        column{2}={mode=math},
        columns={colsep=3pt},
    }
    #1
    \end{tblr}
}{}

\pagestyle{empty}

\begin{document}

\centering
\begin{tblr}{
        colspec={Q[h,l]X[l]Q[h,l]X[l]},
        colsep=3pt,
        rows={\cheight, rowsep=3pt},
        vline{3} = solid,
        hline{2} = solid,
    }
    \tasknumber{1} &
    \begin{mathtask}
        Solve the system: &
        \begin{cases}
            x + y + = 1 \\
            x + y + = 1 \\
            x + y + = 1 \\
            x + y + = 1 \\
            x + y + z = 2
        \end{cases}
    \end{mathtask}
    &
    \tasknumber{2} &
    \begin{mathtask}
        Solve the system: &
        \begin{cases}
            x + y + = 1 \\
            x + y + = 3 \\
            x + y + z = 2
        \end{cases}
    \end{mathtask}
    \\
    \tasknumber{3} &
    \begin{mathtask}
        Solve the equation: &
        x + y + z = 2
    \end{mathtask}
    &
    \tasknumber{50} &
    \begin{mathtask}
        Solve the system: &
        \begin{cases}
            x + y + = 1 \\
            x + y + z = 2
        \end{cases}
    \end{mathtask}
\end{tblr}

\end{document}

enter image description here

2
  • I stumbled upon this issue when trying to solve a different problem. Essentially, I wanted to split a page into 4 areas, draw both horizontal and vertical lines in the middle, and put some info about tasks in the left-hand side upper corners of each task. Then I realised I couldn't do that! I edited my question and included the original problem.
    – Celdor
    Apr 30, 2022 at 9:38
  • @Celdor See my updated answer.
    – L.J.R.
    Apr 30, 2022 at 10:29

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .