Создавайте индивидуальные таблицы

Создавайте индивидуальные таблицы

Мне было интересно, возможно ли создать пользовательские таблицы в LaTeX, подобные показанным на рисунке ниже. Я много искал в Интернете, но не смог найти удовлетворительных решений. Надеюсь, вы сможете мне помочьвведите описание изображения здесь

Это моя попытка.

\documentclass{article}
\usepackage{xcolor}
\usepackage{tabularray}
\definecolor{rowcol}{rgb}{0.7, 0.7, 0.7}

\begin{document}
\begin{table}
  \centering
  \begin{tblr}{
          colspec={Q[c,m,wd=3cm] *{4}{Q[c,m]}},
          cells={font=\large},
          cell{1}{1}={r=2}{},
          cell{1}{2}={c=3}{},
          row{7-8}={bg=rowcol},
          hline{1-Z}={1}{-}{leftpos=0, rightpos=0},
          hline{3}={2}{-}{leftpos=0, rightpos=0},
          vlines,
          vline{2}={2}{-}{},
      }
      & Countries \\
      & 1 & 2 & $\ldots$ & N \\
      Inputs & $Z_{11}$ & $Z_{12}$ & $\ldots$ & $Z_{1N}$ \\
      Inputs & $Z_{21}$ & $Z_{22}$ & $\ldots$ & $Z_{2N}$ \\
      Inputs & $\vdots$ & $\vdots$ & $\vdots$ & $\vdots$ \\
      Inputs & $Z_{N1}$ & $Z_{N2}$ & $\ldots$ & $Z_{NN}$ \\
      Value Added & VA$_1$ & VA$_2$ & $\ldots$ & VA$_4$ \\
      Total Output & $X_1$ & $X_2$ & $\ldots$ & $X_4$ \\
  \end{tblr}
  \caption{Caption}
\end{table}

\end{document}

Не могли бы вы улучшить читабельность (например, слово «Вход» не должно повторяться, и не должно создаваться впечатление, что столбец $N$ отделен) и гарантировать, что таблица не будет плавающей?

решение1

Что-то вроде этого?

Я использовал centerenvironment (с \captionof), чтобы избежать плавания.

\documentclass{article}
\usepackage{xcolor}
\usepackage{tabularray}
\usepackage{caption}
\definecolor{rowcol}{rgb}{0.7, 0.7, 0.7}

\begin{document}
\begin{center}
  \begin{tblr}{
    colspec={Q[c,m,wd=3cm]Q[c,m] *{4}{Q[.7cm,c,m]}},
    cells={font=\large},
    row{Y-Z}={bg=rowcol},
    hline{2,X-Z}={1-Z}{leftpos=0, rightpos=0},
    hline{3-W}={3-Z}{leftpos=0, rightpos=0},
    vline{3,Z}={1-Z}{solid},
    vline{1,2,4-Y}={2-Z}{solid},
    rowsep=6pt,
    }
    & Countries & 1 & 2 & $\ldots$ & N \\
    \SetCell[r=4]{c,m}Inputs &1& $Z_{11}$ & $Z_{12}$ & $\ldots$ & $Z_{1N}$ \\
    &2& $Z_{21}$ & $Z_{22}$ & $\ldots$ & $Z_{2N}$ \\
    & $\vdots$ & $\vdots$ & $\vdots$ & $\vdots$ & $\vdots$ \\
    &$N$& $Z_{N1}$ & $Z_{N2}$ & $\ldots$ & $Z_{NN}$ \\
    \SetCell[c=2]{l}Value Added && VA$_1$ & VA$_2$ & $\ldots$ & VA$_4$ \\
    \SetCell[c=2]{l}Total Output && $X_1$ & $X_2$ & $\ldots$ & $X_4$ \\
  \end{tblr}
  \captionof{table}{Caption}
\end{center}
\end{document}

введите описание изображения здесь

решение2

С {NiceTabular}из nicematrix.

\documentclass{article}
\usepackage{geometry}
\usepackage{xcolor}
\usepackage{nicematrix}

\begin{document}

\renewcommand{\arraystretch}{1.4}
\begin{NiceTabular}{w{c}{2cm}cccw{c}{1cm}c}[hvlines,corners]
                    & countries & 1 & 2 & $\cdots$ & $N$ \\
\Block{4-1}{Inputs} & $1$ & $Z_{11}$ & $Z_{12}$ & $\cdots$ & $Z_{1N}$ \\
                    & $2$ & $Z_{21}$ & $Z_{22}$ & $\cdots$ & $Z_{2N}$ \\
                    \\[1cm]
%                    & $\vdots$  & $\vdots$ & $\vdots$   &  & $\vdots$ \\
                    & $N$ & $Z_{N1}$ & $Z_{N2}$ & $\cdots$ & $Z_{NN}$ \\
\Block[l]{1-2}{Value Added} & & VA$_1$ & VA$_2$ & $\cdots$ & VA$_4$ \\
\Block[l]{1-2}{Total output} & & $X_1$ & $X_2$  & $\cdots$ & $X_4$ \\
\CodeAfter
  \line[shorten=12pt]{3-2}{5-2}
  \line[shorten=12pt]{3-3}{5-3}
  \line[shorten=12pt]{3-4}{5-4}
  \line[shorten=12pt]{3-6}{5-6}
\end{NiceTabular}

\end{document}

Вам нужно несколько компиляций (т.к. nicematrixпод капотом используются узлы PGF/TikZ).

Вывод кода выше

Связанный контент