使用 booktabs 包制作的带有奇怪边框的表格

使用 booktabs 包制作的带有奇怪边框的表格

我想要一个在 Beamer 中看起来像这样的表格:

漂亮的桌子

但我能做的最好的就是:

丑陋的桌子

\documentclass{beamer}
\usepackage{booktabs}
\begin{document}
\frame{
\begin{tabular}{|c|c||c|}\cmidrule{2-3}\noalign{\vskip-\belowrulesep}
\multicolumn{1}{c|}{} & $M_2$ & $a$\\\hline
$M_1$ & $M_3$ &\\\noalign{\vskip-\aboverulesep}\cmidrule{1-2}
    \morecmidrules\cmidrule{1-2}\noalign{\vskip-\belowrulesep}
$b$ & \multicolumn{1}{c}{} & \multicolumn{1}{c|}{$x$}\\\hline
\end{tabular}
}
\end{document}

我想要的桌子可以吗?

答案1

使用以下软件包的解决方案tabularray

\documentclass{beamer}
\usepackage{tabularray}
\begin{document}
\frame{
    \begin{tblr}{
        colspec = { *{3}{c }},
        hline{1} = {1}{2-3}{},
        hline{2,4} = {1}{1-3}{},
        hline{3} = {1}{1-2}{rightpos = 0},
        hline{3} = {2}{1-2}{},
        vline{1} = {1}{2-3}{},
        vline{2} = {1}{1-3}{},
        vline{3} = {1}{1-2}{},
        vline{3} = {2}{1-2}{belowpos = 1},
        vline{4} = {1}{1-3}{belowpos = 1},
    }
     & $M_2$ & $a$ \\ 
    $M_1$ & $M_3$ & \\
    $b$ &  & $x$ \\
    \end{tblr}
}
\end{document}

在此处输入图片描述


如果你想要在右侧的垂直线之间获得连续的间隙,最好使用nicematrix结合了 Ti 优势的包Z 与表格的可能性(至少tabularray在这种情况下不会给你一个好的结果):

\documentclass{beamer}
\usepackage{nicematrix, tikz}
\begin{document}
\frame{
    \begin{NiceTabular}{ *{3}{c} }
     & $M_2$ & $a$ \\ 
    $M_1$ & $M_3$ & \\ 
    $b$ &  & $x$ \\
    \CodeAfter
        \begin{tikzpicture}
            \draw 
                (1-|2) -- 
                ([xshift=-1pt]1-|3) -- 
                ([xshift=-1pt, yshift=1pt]3-|3) -- 
                ([yshift=1pt]3-|1) -- 
                (2-|1) -- (2-|2) -- cycle;
            \draw 
                ([xshift=1pt]1-|3) -- 
                (1-|4) -- (4-|4) -- (4-|1) --
                ([yshift=-1pt]3-|1) -- 
                ([xshift=1pt, yshift=-1pt]3-|3) -- 
                cycle;
            \draw (2-|2) -- ([xshift=-1pt]2-|3)
                ([xshift=1pt]2-|3) -- (2-|4);
            \draw (2-|2) -- ([yshift=1pt]3-|2) 
                ([yshift=-1pt]3-|2) -- (4-|2);
        \end{tikzpicture}
    \end{NiceTabular}
}
\end{document}

在此处输入图片描述

答案2

Tikz 为你而设 :-)

\documentclass{beamer}
\usepackage{tikz}
\usetikzlibrary{positioning}
\begin{document}
\begin{frame}
  \begin{tikzpicture}[
    , thick
    , n/.style = {
      , minimum width = 10mm
      , minimum height = 6mm
      , draw
    }
    , outer sep = 0
    , node distance = 0 and 0
  ]
    \node (M2) [n] {$M_2$};
    \node (M3) [below = of M2, n] {$M_3$};
    \node (M1) [left = of M3, n] {$M_1$};
    \node (a) [right = 1mm of M2, n] {$a$}; % add , minimum width = 7mm if you want narrower node
    \node (b) [below = 1mm of M1, n] {$b$};
    \node (x) [below = 7mm of a.south, minimum height = 6mm] {$x$};
    \draw (M2.north east) -- (a.north west);
    \draw (M2.south east) -- (a.south west);
    \draw (a.south west) |- (b.north east);
    \draw (a.south east) |- (b.south east);
  \end{tikzpicture}%
\end{frame}
\end{document}

结果

答案3

hhline包装;

\documentclass{beamer}
\usepackage{hhline}

\begin{document}
\begin{frame}
\begin{center}
\renewcommand\arraystretch{1.2}
    \begin{tabular}{|c|c||c|}
    \hhline{~|-|-|}
\multicolumn{1}{c|}{}
        & $M_2$ & $a$   \\
    \hhline{-|--|}
$M_1$   & $M_3$ &       \\
    \hhline{:=:=:b|~|}
$b$     & \multicolumn{1}{c}{}
                &  $x$  \\
    \hline
    \end{tabular}
\end{center}
\end{frame}
\end{document}

在此处输入图片描述

答案4

tabular借助一个简单的小补丁array来玩弄列间距(@{}):

姆韦

\documentclass{article}
\usepackage{array}
\begin{document}\sffamily\extrarowheight2pt
\begin{tabular}{|c|c|@{}p{2pt}@{}|l|}
\cline{2-4}
\multicolumn{1}{c|}{}&M2&&a\\\hline
M1&M3&&\\\cline{1-2}
\multicolumn{3}{c}{\vspace*{-12pt}}&%
\multicolumn{1}{@{\kern-.4pt\rule[8pt]{.4pt}{2.6pt}}c|}{}\\\cline{1-3}
b & \multicolumn{2}{c}{} &  x \\
\hline
\end{tabular}
\end{document}

相关内容