我怎样才能在乳胶中改善这张表的样式?

我怎样才能在乳胶中改善这张表的样式?

我想将表格的所有元素置于中心,并改善这个元素的样式。

\begin{table}[h]
\begin{tabular}{|l|r|l|l|}
\hline
\multicolumn{1}{|c|}{text} & \multicolumn{3}{r|}{Aproach}                                                                                                                                                                                                                                                                                                                                                                                                                                                \\ \hline
another text                              & other one                                                                                                                                                            & another one                                                                                                                                                         & other                                                                                                                                                     \\ \hline
something                  & \begin{tabular}[c]{@{}r@{}}another fancy text:\\ another text:\\ another text:\\ another one text:\\ another one text:\\ another text:\\ some text:\\ F-Beta another text:\end{tabular} & \begin{tabular}[c]{@{}l@{}}Exactitud:\\ another text:\\ another text:\\ another one text:\\ another one text:\\ another text:\\ some text:\\ another one textta another text:\end{tabular} & \begin{tabular}[c]{@{}l@{}}Exactitud:\\ another text:\\ another text:\\ another one text:\\ another one text:\\ another text:\\ some text:\\ F-Beta another text:\end{tabular} \\ \hline
                                     & 0.01                                                                                                                                                           &                                                                                                                                                                &                                                                                                                                                                \\ \hline
Gnu                                  & 92.50                                                                                                                                                          &                                                                                                                                                                &                                                                                                                                                                \\ \hline
Emu                                  & 33.33                                                                                                                                                          &                                                                                                                                                                &                                                                                                                                                                \\ \hline
Armadillo                            & 8.99                                                                                                                                                           &                                                                                                                                                                &                                                                                                                                                                \\ \hline
Total:                               & \multicolumn{1}{l|}{}                                                                                                                                          &                                                                                                                                                                &                                                                                                                                                                \\ \hline
\end{tabular}
\end{table}

在此处输入图片描述

我怎样才能使上表看起来如下所示?

在此处输入图片描述

答案1

% arara: pdflatex
% arara: pdflatex

\documentclass[10pt,letterpaper]{article}
\usepackage{booktabs}
\usepackage{siunitx}
\newcommand{\cenMultlCell}[2][c]{\begin{tabular}[#1]{@{}c@{}}#2\end{tabular}}
\usepackage[colorlinks=true, linkcolor=black]{hyperref}

\begin{document}
\begin{table}
    \footnotesize\centering % needed, as table is to wide
    \begin{tabular}{lS[table-format=2.2]SS} % supposing that you want to put numbers in the emty cells
        \toprule
        text & \multicolumn{3}{c}{Aproach} \\\cmidrule(l){2-4}
        another text & {other one} & {another one} & {other} \\\midrule
        something 
        & {\cenMultlCell{another fancy text:\\ another text:\\ another text:\\ another one text:\\ another one text:\\ another text:\\ some text:\\ F-Beta another text:}} 
        & {\cenMultlCell{Exactitud:\\ another text:\\ another text:\\ another one text:\\ another one text:\\ another text:\\ some text:\\ another one text:}}
        & {\cenMultlCell{Exactitud:\\ another text:\\ another text:\\ another one text:\\ another one text:\\ another text:\\ some text:\\ F-Beta another text:}} \\\midrule
        & 0.01 & & \\
        Gnu & 92.50 & & \\
        Emu & 33.33 & & \\
        Armadillo & 8.99 & & \\\midrule\midrule
        Total: & & & \\ \bottomrule
    \end{tabular}
    \caption{your caption}\label{tab:label}
\end{table}

A reference to \autoref{tab:label}.
\end{document}

在此处输入图片描述

答案2

我有以下建议:

  • 要使环境中某列的元素居中tabular,请使用ccolumn 类型而不是lr

  • 要将tabular环境置于table环境的中心,请使用\centering指令。

  • 您有几个\multicolumn{1}{|c|}{...}“包装器”语句。它们并没有造成太大的损害,但似乎也没有必要。我会忽略它们。

  • 定位[c]说明符是tabular环境的默认设置。不指定它可以减少混乱。

  • 您似乎提供了很多空格字符来直观地格式化表格材料。我会在输入中使用更多换行符,以使输入材料更容易被人眼解析。

\documentclass{article}
\usepackage[margin=1in]{geometry} % choose page margins appropriately
\begin{document}
\begin{table}[h]
\centering
\begin{tabular}{|c|c|c|c|}
\hline
text & \multicolumn{3}{c|}{Approach}
\\ \hline
another text & other one & another one & other 
\\ \hline
something & 
\begin{tabular}{@{}c@{}}
   another fancy text:\\ 
   another text:\\ 
   another text:\\ 
   another one text:\\ 
   another one text:\\ 
   another text:\\ 
   some text:\\ 
   F-Beta another text:
\end{tabular} &
\begin{tabular}{@{}c@{}}
   Exactitud:\\ 
   another text:\\ 
   another text:\\ 
   another one text:\\ 
   another one text:\\ 
   another text:\\ 
   some text:\\ 
   another one textta another text:
\end{tabular} & 
\begin{tabular}{@{}c@{}}
   Exactitud:\\ 
   another text:\\ 
   another text:\\ 
   another one text:\\ 
   another one text:\\ 
   another text:\\ 
   some text:\\ 
   F-Beta another text:
\end{tabular}
\\ \hline
          &  0.01 & & \\ \hline
Gnu       & 92.50 & & \\ \hline
Emu       & 33.33 & & \\ \hline
Armadillo &  8.99 & & \\ \hline
Total:    & & & 
\\ \hline
\end{tabular}
\end{table}
\end{document} 

在此处输入图片描述

答案3

只需在表格定义中将 r 和 l 替换为 c 即可。稍微重组一下代码,就能让编辑变得更容易。

\documentclass[10pt,letterpaper]{article}

\begin{document}
\begin{table}[h]
\begin{tabular}{|c|c|c|c|}\hline
\multicolumn{1}{|c|}{text} & \multicolumn{3}{c|}{Aproach}\\ \hline
another text  & other one & another one      & other     \\ \hline
something     & \begin{tabular}[c]{@{}c@{}}
                another fancy text:\\ 
                another text:\\ 
                another text:\\ 
                another one text:\\ 
                another one text:\\ 
                another text:\\ 
                some text:\\
                F-Beta another text:
                \end{tabular}        
              & \begin{tabular}[c]{@{}c@{}}
                    Exactitud:\\ 
                    another text:\\ 
                    another text:\\ 
                    another one text:\\ 
                    another one text:\\ 
                    another text:\\ 
                    some text:\\ 
                    another one textta another text:
                \end{tabular}              
               & \begin{tabular}[c]{@{}c@{}}
                    Exactitud:\\ 
                    another text:\\ 
                    another text:\\ 
                    another one text:\\ 
                    another one text:\\ 
                    another text:\\ 
                    some text:\\ 
                    F-Beta another text:
                    \end{tabular} \\ \hline
       & 0.01   &    &            \\ \hline
Gnu    & 92.50  &    &                   \\ \hline
Emu    & 33.33  &    &     \\ \hline
Armadillo       & 8.99    &      &     \\ \hline
Total:   & \multicolumn{1}{l|}{}      &  &   \\ \hline
\end{tabular}
\end{table}
\end{document}

在此处输入图片描述

相关内容