在 tabularray 中将 tikzpicture 居中

在 tabularray 中将 tikzpicture 居中

在我的表格中,我希望第二个 tikzpicture 列居中(如单词“convergent”),并且第四列单元格中的每个单词也居中(“biconvex”相对于镜头表示位于底部中心)

在此处输入图片描述

我的代码:

    \documentclass{article}

\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc} 
\usepackage[french]{babel}
\usepackage{tabularray}
\usepackage{tikz}

\begin{document}
\begin{tblr}{
vspan=even, hspan=minimal,
hline{2,5}={blue},
colspec={Q[c] Q[c] Q[c] Q[c]}, rowspec={Q[m] Q[m] Q[m] Q[m] Q[m] Q[m] Q[m]},
cell{2}{1}={r=3}{c},
cell{5}{1}={r=3}{c},
colsep=3pt,
row{1}={cmd=\textbf},
}
type de lentille & représentation schématique & forme & représentation\\
convergente & \begin{tikzpicture}[scale=0.5]
    \draw[<->] (0,0) -- (0,2);
\end{tikzpicture}& biconvexe & \begin{tikzpicture}[scale=0.5]
    \draw (0,-1) to[bend left=30] (0,1) to [bend left=30] (0,-1);

\end{tikzpicture}\\
 &   & plan convexe & \begin{tikzpicture}[scale=0.5]
    \draw (0,-1) to[bend left=30] (0,1) to (0,-1);

\end{tikzpicture}\\
 &  & ménisque convergent & \begin{tikzpicture}[scale=0.5]
    \draw (0,-1) to[bend left=40] (0,1) to [bend right=20] (0,-1);

\end{tikzpicture}\\
divergente &  & biconcave & \\
& & plan concave & \\
& & ménisque divergent & \\
\end{tblr}

\end{document}

答案1

\documentclass[border=1cm]{standalone}
\usepackage{tabularray}
\usepackage{tikz}
\begin{document}
\begin{tblr}{
vspan=even, hspan=minimal,
hline{2,5}={blue},
colspec={Q[c] Q[c] Q[c] Q[c]}, rowspec={Q[m] Q[m] Q[m] Q[m] Q[m] Q[m] Q[m]},
cell{2}{1}={r=3}{c},
cell{2}{2}={r=3}{c},
cell{5}{1}={r=3}{c},
colsep=3pt,
row{1}={cmd=\textbf},
}
type de lentille & représentation schématique & forme & représentation\\
convergente & \tikz \draw[<->] (0,0) -- (0,2); & biconvexe & \\
&  & plan convexe & \\
&  & ménisque convergent & \\
divergente &  & biconcave & \\
& & plan concave & \\
& & ménisque divergent & \\
\end{tblr}
\end{document}

带有文本和双箭头的表格

答案2

我会按照以下方式编写您的表格:

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[french]{babel}
\usepackage{tabularray}
\UseTblrLibrary{booktabs}
\usepackage{tikz}


\begin{document}
    \begin{table}[ht]
    \tikzset{every picture/.style={baseline, yscale=0.5}}
\begin{tblr}{colspec={@{} Q[c,wd=5em] Q[c,wd=8em] c Q[c,m] @{}}, 
             rowsep=3pt,
             row{1}={cmd=\textbf, m}, 
            }
    \toprule[blue]
type de lentille
    & représentation schématique
        & forme 
            & représentation        \\
    \midrule[blue]
\SetCell[r=3]{m}    convergente 
    &   \SetCell[r=3]{m}
        \tikz\draw[<->] (0,-3) -- (0,3);    
        & biconvexe 
            &   \tikz\draw (0,-1) to[bend left] (0,1) to [bend left] (0,-1);
                                    \\
    &   \tikz[baseline]
            \draw[<->] (0,-2) -- (0,2);
        & plan convexe 
            &   \tikz\draw (0,-1) to[bend left] (0,1) to (0,-1);
                                    \\
    &   & ménisque convergent 
            &   \tikz\draw (0,-1) to[bend left] (0,1) to [bend right=15] (0,-1);
                                    \\
     \midrule[blue]
    &   &   biconcave             
        &   \tikz\draw (-.5,-1) to[bend right] (-0.5,1) -- (0.5,1)  
                                to[bend right] (0.5,-1) -- cycle;
                                    \\
divergente
    &   & plan concave         
        &   \tikz\draw (-.5,-1) to[bend right] (-0.5,1) 
                                -- (0,1) |- cycle;
                                    \\
    &   & ménisque divergent 
            &   \tikz\draw (0,-1) to[bend right=15] (0,1) to [bend left] (0,-1);
                                    \\
    \bottomrule[blue]
\end{tblr}
    \end{table}
\end{document}

在此处输入图片描述

答案3

以下是基于用户 egreg 给我的解决方案的另一种解决方案:

\documentclass{article}

\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc} 
\usepackage[french]{babel}
\usepackage{tabularray}
\usepackage{tikz}
\AtBeginDocument{\sbox0{$x$}}% to be sure the math fonts are computed
\tikzset{baseshift/.style={yshift=-\the\dimexpr\fontdimen22\textfont2}}


\begin{document}
    \begin{tblr}{
            vspan=even, hspan=minimal,
            hline{2,5}={blue},
            colspec={Q[c] Q[c] Q[c] Q[c]}, rowspec={Q[m] Q[m] Q[m] Q[m] Q[m] Q[m] Q[m]},
            cell{2}{1}={r=3}{c},
            cell{5}{1}={r=3}{c},
            colsep=3pt,
            row{1}={cmd=\textbf},
        }
        type de lentille & représentation schématique & forme & représentation\\
        convergente & & biconvexe & \begin{tikzpicture}[scale=0.5,baseline={([baseshift]current bounding box.center)}]
            \draw (0,-1) to[bend left=30] (0,1) to [bend left=30] (0,-1);
            
        \end{tikzpicture}\\
        & \begin{tikzpicture}[scale=0.5,baseline={([baseshift]current bounding box.center)}]
            \draw[<->] (0,0) -- (0,2);
        \end{tikzpicture}  & plan convexe & \begin{tikzpicture}[scale=0.5,baseline={([baseshift]current bounding box.center)}]
            \draw (0,-1) to[bend left=30] (0,1) to (0,-1);
            
        \end{tikzpicture}\\
        &  & ménisque convergent & \begin{tikzpicture}[scale=0.5,baseline={([baseshift]current bounding box.center)}]
            \draw (0,-1) to[bend left=40] (0,1) to [bend right=20] (0,-1);
            
        \end{tikzpicture}\\
        divergente &  & biconcave & \\
        & & plan concave & \\
        & & ménisque divergent & \\
    \end{tblr}
    
\end{document}

在此处输入图片描述

相关内容