Tabulary 包无法打印具有正确大小的表格

Tabulary 包无法打印具有正确大小的表格

我想重新创建这个表: 在此处输入图片描述 我花了几个小时来理解表格LaTeX并弄清楚我需要什么包。但我得到的只是沮丧。

我的 MWE 输出下表,我期望它具有线宽的宽度(如指定),但事实并非如此。我LaTeX已经使用了几个月,但从未真正使用过表格,而且它们对我来说感觉不实用。现在,我该如何让表格达到正确的大小?

在此处输入图片描述

梅威瑟:

\documentclass[12pt, listof=totoc, numbers=noenddot]{scrartcl} 
\usepackage{booktabs}
\usepackage{tabulary}
\begin{document}
This is an MWE and some Text to see how much space there is in one Line... more than enough.
\begin{table}[!h]
    \caption{My Tabel}
    \centering
    \begin{tabulary}{\linewidth}{L|C C C C C C} \toprule % expecting the table to have the width of \linewidth
        Temperaturbereich in C 
        & \multicolumn{6}{c}{
        \begin{tabular}{c|c}$T_1 = 1$ & $T_2 = 2$\end{tabular}} 
        \\ \midrule
        Approximationsfunktion  
        & \multicolumn{6}{c}{$\displaystyle c_{Fe2O3} = \frac{123}{321}$}
        \\ \midrule
        Konstanten 
        & \multicolumn{2}{c}{$123$} & \multicolumn{2}{c}{$321$} & \multicolumn{2}{c}{$444$}
        \\ \bottomrule
    \end{tabulary}
    \label{tab:Koeff-Fe2O3}
\end{table}
\end{document}

答案1

作为对 @Mico 的精彩回答 (+1) 的补充,通过使用包tabularray。它使代码更短一些:

\documentclass[12pt, listof=totoc, numbers=noenddot]{scrartcl}
\usepackage{tabularray} % for 'tblr' environment and 'X' col. type
\UseTblrLibrary{amsmath,% for \dfrac
                siunitx}% for unit \degreeCelsius
\usepackage{mhchem}     % for '\ce' macro

\begin{document}
    \begin{table}[!h]
\caption{My Table}
\label{tab:Koeff-Fe2O3}

\begin{tblr}{hlines, vlines,
             colspec = { l *{6}{X[c, mode=math]} },
             rowsep  = 4pt
             }
Temperaturbereich in \unit{\degreeCelsius}
    &   \SetCell[c=3]{} T_1 = 1
        &   &   &   \SetCell[c=3]{} T_2 = 2
                    &   &                   \\
Approximationsfunktion
    &   \SetCell[c=6]{} c^{}_{\ce{Fe2O3}} = \dfrac{123}{321}
        &   &   &   &   &                   \\
Konstanten
    &   \SetCell[c=2]{} 123
        &   &   \SetCell[c=2]{} 456
                &   &   \SetCell[c=2]{} 789
                        &                   \\
\end{tblr}
    \end{table}
\end{document}

在此处输入图片描述

答案2

正如 OP 的询问下面的评论所指出的,tabulary机器似乎不适合手头的任务。这里有一个使用tabularx机器的解决方案。

在此处输入图片描述

\documentclass[12pt, listof=totoc, numbers=noenddot]{scrartcl} 
\usepackage{tabularx} % for 'tabularx' env. and 'X' col. type
\usepackage{amsmath}  % for '\dfrac' macro
\usepackage{mhchem}   % for '\ce' macro

\newcolumntype{C}{>{\centering\arraybackslash}X} % centered version of 'X'
\newcommand\mc[3]{% handy shortcut macro
    \multicolumn{#1}{>{\hsize=\dimexpr #2 \relax}C|}{#3}}

\begin{document}

\begin{table}[!h]
\setlength\extrarowheight{2pt} % for a less-cramped "look"
\caption{My Table}
\label{tab:Koeff-Fe2O3}

\begin{tabularx}{\linewidth}{ | l | *{6}{C|} } 
\hline 
Temperaturbereich in C 
  & \mc{3}{3\hsize+4\tabcolsep+2\arrayrulewidth}{$T_1 = 1$}
  & \mc{3}{3\hsize+4\tabcolsep+2\arrayrulewidth}{$T_2 = 2$}
\\ \hline
Approximationsfunktion  
  & \multicolumn{6}{c|}{%
    $c^{}_{\ce{Fe2O3}} = \dfrac{123^{\mathstrut}}{321_{\mathstrut}}$}
\\ \hline
Konstanten 
  & \mc{2}{2\hsize+2\tabcolsep+1\arrayrulewidth}{$123$} 
  & \mc{2}{2\hsize+2\tabcolsep+1\arrayrulewidth}{$321$} 
  & \mc{2}{2\hsize+2\tabcolsep+1\arrayrulewidth}{$444$}
\\ \hline
\end{tabularx}
    
\end{table}
\end{document}

相关内容