表格标题和 \tikzpicture 单元格在 tabularray 包中未垂直居中,并且 \polylongdiv 在表格环境中不起作用

表格标题和 \tikzpicture 单元格在 tabularray 包中未垂直居中,并且 \polylongdiv 在表格环境中不起作用
\documentclass{article}
\usepackage[a4paper, portrait, margin=0.5in]{geometry}
\usepackage[table]{xcolor}
\usepackage[most]{tcolorbox}
\usepackage{amsmath}
\usepackage{tabularray}
\usepackage{polynom}

\begin{document}
\large

\newenvironment{tablemath}
    {
    \begin{array}{@{} l}
    }
    {
    \end{array}
    }

\begin{center}
\begin{tblr}{hlines, vlines,
             colspec={Q[c,m, wd=1.5cm] Q[l,m, wd=9.5cm, mode=dmath]
                      Q[r,m, wd=1cm, font=\bfseries] Q[l, m, wd=4.5cm]},
             row{1} = {font=\bfseries, mode=text},
             row{2-Z} ={rowsep=7pt},
             }
    \SetRow{gray!20} A & B & C & D \\
    Regular Row & \begin{tablemath}
                  f(3) = 100  \\
                  a = \dfrac{50}{21} - \dfrac{13}{42}b
                  \end{tablemath} & C1 & D1 \\
    Tikz Row & \begin{tikzpicture}[scale=1.5]
                      \draw[thick,<->] (-2,0) -- (2,0);
                      \draw[thick] (0,0.1) -- (0,-0.1) node[anchor=north] {$0$};
                      \draw[thick] (-1.5,0.1) -- (-1.5,-0.1) node[anchor=north] {$-1.5$};
                      \draw[thick] (-1.5,0.25) -- (0,0.25);
                      \draw[fill=white] (-1.5,0.25) circle (0.05);
                      \draw[fill=white] (0,0.25) circle (0.05);
                      \end{tikzpicture} & \textbf{C2} & D2 \\
    Long Division Row & \polylongdiv{5x^5-4x^4+25x^3-x^2+36x-2}{x^3-x^2+3x-3} & \textbf{C3} & D3 \\
\end{tblr}
\end{center}

\polylongdiv{5x^5-4x^4+25x^3-x^2+36x-2}{x^3-x^2+3x-3}
    
\end{document}

上述代码给出以下结果: 在此处输入图片描述

表格标题(ABCD 行)和 \tikzpicture(Tikz 行)单元格未垂直居中。有人能告诉我如何使这些行垂直居中吗?

\polylongdiv 命令在该表格环境中也无法工作,但是在其他地方它可以工作(如表格外所示)。有人可以帮助让命令像这样工作吗?(同时保持垂直居中)

答案1

编辑:

  • 列标题垂直居中。要查看此内容,请将带有下划线的字母添加到标题文本中,例如 g、j、p、... 如果列标题文本中仅包含大写字母,那么您也可以添加row{1}规范 abovesep+=2pt,这将使此类列标题垂直居中(请参阅下面的 MWE)。
  • 对于图像:tikzpicture您需要添加选项baseline
  • 因为\polylongdiv您需要执行以下操作:
    • 增加列宽,例如使用X列并将最后一列的宽度从 4.5 厘米减少到 3.5 厘米,
    • 将方程局部移位\polylongdiv到单元格顶部(通过局部规定的选项h),
\documentclass{article}
\usepackage[a4paper, portrait, margin=0.5in]{geometry}
\usepackage{tikz}
\usetikzlibrary{arrows.meta}

\usepackage{xcolor}
\usepackage{tabularray}
\UseTblrLibrary{amsmath}
\usepackage{polynom}

\begin{document}
\large

\newenvironment{tablemath}
    {
    \begin{array}{@{} l}
    }
    {
    \end{array}
    }

\begin{center}
\begin{tblr}{hlines, vlines,
             colspec= {Q[c,m, wd=1.5cm] X[l,m, mode=dmath]
                       Q[r,m, wd=1cm, font=\bfseries] Q[l, m, wd=3.5cm]},
             row{1} = {font=\bfseries, mode=text, bg=gray!20, abovesep+=2pt},
             row{2-Z} ={rowsep=7pt},
             }
A   & B & C & D \\
Regular Row 
    &   \begin{tablemath}
            f(3) = 100  \\
            a = \dfrac{50}{21} - \dfrac{13}{42}b
        \end{tablemath}     & C1            & D1 \\
Tikz Row 
    &   \begin{tikzpicture}[c/.tip = {{Circle[open, length=0 8, sep=-3.2]}},
                            font=\small, baseline=-1ex]
            \draw[thick,<->] (-2,0) -- (2,0);
            \draw[thick] (0,0.1) -- (0,-0.1) node[below] {$0$};
            \draw[thick] (-1.5,0.1) -- (-1.5,-0.1) node[below] {$-1.5$};
            \draw[thick,c-c] (-1.5,0.4) -- (0,0.4);
        \end{tikzpicture}   &  C2           & D2 \\
Long Division Row 
    &   \SetCell{h}
        \polylongdiv{5x^5-4x^4+25x^3-x^2+36x-2}{x^3-x^2+3x-3} 
                            &   C3          & D3 \\
\end{tblr}
\end{center}

\polylongdiv{5x^5-4x^4+25x^3-x^2+36x-2}{x^3-x^2+3x-3}

\end{document}

在此处输入图片描述

答案2

draw为了更好地了解问题,我在节点中添加了选项,并\vruletikzpicture

在此处输入图片描述

outer sep=20pt

在此处输入图片描述

\adjustbox{valign=m}{

在此处输入图片描述

没有\adjustbox{valign=m}{与,inner sep=0pt,yshift=-2pt

在此处输入图片描述

随着代码的 zarko

    \documentclass{article}
    \usepackage[a4paper, portrait, margin=0.5in]{geometry}
    \usepackage{tikz}
    \usetikzlibrary{arrows.meta}

    \usepackage{xcolor}
    \usepackage{tabularray}

    \UseTblrLibrary{amsmath}
    \usepackage{polynom}
    \usepackage{adjustbox}

    \begin{document}
    \large

    \newenvironment{tablemath}
        {
        \begin{array}{@{} l}
        }
        {
        \end{array}
        }

    \begin{center}
    \begin{tblr}{hlines, vlines,
                colspec= {Q[c,m, wd=1.5cm] X[l,m]},
                row{1} = {font=\bfseries, mode=text, bg=gray!20},
                row{2-Z} ={rowsep=7pt},
                }
    A  & B\\
    Tikz Row
    &
    %\adjustbox{valign=m}{%
    \begin{tikzpicture}[c/.tip = {{Circle[open, length=0 8, sep=-3.2]}},
                font=\small, baseline]
                %\draw(0,0)--(0,-0.7);
                \draw[thick,<->] (-2,0) -- (2,0);
                % \draw[thick] (0,0.1) -- (0,-0.1) node[below,draw,inner sep=0pt,yshift=-2pt] {$0$};
                % \draw[thick] (-1.5,0.1) -- (-1.5,-0.1) node[below,draw,inner sep=0pt,yshift=-2pt] {$-1.5$};
                \draw[thick] (0,0.1) -- (0,-0.1) node[below,inner sep=0pt,yshift=-2pt] {$0$};
                \draw[thick] (-1.5,0.1) -- (-1.5,-0.1) node[below,inner sep=0pt,yshift=-2pt] {$-1.5$};
                \draw[thick,c-c] (-1.5,0.4) -- (0,0.4);
            \end{tikzpicture}%
            \vrule
            %}% 
    \end{tblr}
    \end{center}
    \end{document}

相关内容