如何在单列页面中美观地显示三列小表格?

如何在单列页面中美观地显示三列小表格?

表格在整个页面上看起来不太好看。如何才能让它看起来更美观一些,以尽量减少周围的空白?

\documentclass[listof=totoc,a4paper,11pt,oneside,chapterprefix=true,sfdefaults=false]{scrbook}
\usepackage[margin=1in]{geometry} 
%Table packages
\usepackage[figuresright]{rotating}
%\setlength{\rotFPtop}{0pt plus 1fil}
\usepackage{booktabs, makecell, tabularx, ragged2e}
\renewcommand{\theadfont}{\normalsize}
\renewcommand\theadgape{}
\newcolumntype{L}{>{\RaggedRight}X}
\newcolumntype{P}[1]{>{\RaggedRight\hspace{0pt}}p{#1}}

\begin{document}
% For tables use
\begin{table}
% table caption is above the table
\caption{Comparison between smartphone and MPU+MCU based monitoring}
\label{swa_tab:2}       % Give a unique label
% For LaTeX tables use
\begin{tabularx}
                {\linewidth}{>{\raggedright\arraybackslash}p{1in}
                            >{\raggedright\arraybackslash}p{1in}
                             >{\raggedright\arraybackslash}p{0.75in}
                             >{\raggedright\arraybackslash}p{0.5in}
                             }
\toprule
\thead{Features} &\thead{ Smartphone} & \thead{MCU+MPU}\\
\midrule\\
\textbf{Device Type} & General purpose & Dedicated \\
\addlinespace
\textbf{Cost} & High~(US\$100 or more) &  Low~(US\$10 or less)\\
\addlinespace
\textbf{Form Factor} & 6-7 inches & 2-3 inches\\
\addlinespace
\textbf{Power Consumption} & More than 5 watt & less than 1 watt\\
\addlinespace
\textbf{Device Integration} &Very Difficult& Easy to integrate\\
\addlinespace
\textbf{Ease of use}& Difficult for seniors & Easy for seniors\\
\addlinespace
\textbf{Durability \& parts} & Fragile\&costly spare & Durable\&Cheap\\
\noalign{\smallskip}\hline
\end{tabularx}
\end{table}
\end{document}

答案1

由于单元格内容都不是特别长,我建议使用普通tabular环境。哦,不要过量使用大胆的东西。设计良好的表格不需要它;事实上,大胆的很快就会成为一种不必要的干扰。

在此处输入图片描述

\documentclass[listof=totoc,a4paper,11pt,oneside,
  chapterprefix=true,sfdefaults=false]{scrbook}
\usepackage[margin=1in]{geometry} 
%% I've kept the preamble purposefully sparse
\usepackage{booktabs, array, ragged2e}
\newcolumntype{P}[1]{>{\RaggedRight\hspace{0pt}}p{#1}}
\usepackage{threeparttable}

\begin{document}

\begin{table}
\centering
\begin{threeparttable}
\caption{Comparison between smartphone and MPU+MCU based monitoring}
\label{swa_tab:2}       % Give a unique label

\begin{tabular}{@{} l l l @{}}
\toprule
Features & Smartphone & MCU+MPU \\
\midrule
Device type & General purpose & Dedicated \\

Cost & High~(US\$100 or more) &  Low~(US\$10 or less)\\

Form Factor & 6--7 inches & 2--3 inches\\

Power consumption & More than 5 Watt & less than 1 Watt\\

Device integration &Very difficult& Easy to integrate\\

Ease of use & Difficult for seniors & Easy for seniors\\

Durability \& parts & Fragile \& costly spare & Durable \& cheap\\
\bottomrule
\end{tabular}
\end{threeparttable}

\end{table}
\end{document}

答案2

  1. tabularx如果没有列的话,使用X将不起作用。

  2. 如果您的表有三列,请不要分配其中四列。

  3. 这是风格上的,但是粗体在像这样的表格中并不适合用在表格中。

  4. \noalign{\smallskip}\hline是错误的,请使用\bottomrule

  5. 数字范围应为6--7,带有短破折号。

  6. 如果想要表格上方的标题,请使用\captionabove(因为scrbook):应该标题和表格之间有空格。

该图还显示了页面边界:

在此处输入图片描述

代码(仅包含必要的包):

\documentclass[
  listof=totoc,
  a4paper,
  11pt,
  oneside,
  chapterprefix=true,
  sfdefaults=false
]{scrbook}
\usepackage[margin=1in]{geometry} % why inches?

\usepackage{booktabs}

\begin{document}

\begin{table}
\centering

\captionabove{Comparison between smartphone and MPU+MCU based monitoring}
\label{swa_tab:2}       % Give a unique label

\begin{tabular}{@{} l l l @{}}
\toprule
Features & \multicolumn{1}{c}{Smartphone} & \multicolumn{1}{c}{MCU+MPU}\\
\midrule
Device Type & General purpose & Dedicated \\
\addlinespace
Cost & High (US\$100 or more) &  Low (US\$10 or less)\\
\addlinespace
Form Factor & 6--7 inches & 2--3 inches\\
\addlinespace
Power Consumption & More than 5 watt & less than 1 watt\\
\addlinespace
Device Integration & Very Difficult & Easy to integrate\\
\addlinespace
Ease of use & Difficult for seniors & Easy for seniors\\
\addlinespace
Durability \& parts & Fragile \& costly spare & Durable \& Cheap\\
\bottomrule
\end{tabular}

\end{table}

\end{document}

您可能希望扩展表格以覆盖整个文本宽度;在这种情况下,使用tabular*,但我没有看到真正的改进(说实话,表格看起来更糟):

在此处输入图片描述

\documentclass[
  listof=totoc,
  a4paper,
  11pt,
  oneside,
  chapterprefix=true,
  sfdefaults=false
]{scrbook}
\usepackage[margin=1in]{geometry} % why inches?

\usepackage{booktabs}

\begin{document}

\begin{table}
\centering

\captionabove{Comparison between smartphone and MPU+MCU based monitoring}
\label{swa_tab:2}       % Give a unique label

\begin{tabular*}{\textwidth}{@{\extracolsep{\fill}} l l l @{}}
\toprule
Features & \multicolumn{1}{c}{Smartphone} & \multicolumn{1}{c}{MCU+MPU}\\
\midrule
Device Type & General purpose & Dedicated \\
\addlinespace
Cost & High (US\$100 or more) &  Low (US\$10 or less)\\
\addlinespace
Form Factor & 6--7 inches & 2--3 inches\\
\addlinespace
Power Consumption & More than 5 watt & less than 1 watt\\
\addlinespace
Device Integration & Very Difficult & Easy to integrate\\
\addlinespace
Ease of use & Difficult for seniors & Easy for seniors\\
\addlinespace
Durability \& parts & Fragile \& costly spare & Durable \& Cheap\\
\bottomrule
\end{tabular*}

\end{table}

\end{document}

最后,第一个没有\addlinespace命令的实现(未扩展),我发现这是最有吸引力的。

在此处输入图片描述

答案3

  • 定义了四列,但只使用了三列
  • tabularx表应该至少有一个X列类型,你没有任何
  • 可能的解决方案:
\documentclass[11pt, la4paper,
                istof=totoc,
                oneside,
                chapterprefix=true,
                sfdefaults=false]{scrbook}
\usepackage[showframe,      % remove this option in the real document
            margin=1in]{geometry}
%Table packages
\usepackage[figuresright]{rotating}
%\setlength{\rotFPtop}{0pt plus 1fil}
\usepackage{booktabs, makecell, tabularx, ragged2e}
\renewcommand{\theadfont}{\normalsize}
\renewcommand\theadgape{}
\newcolumntype{L}[1]{>{\hsize=#1\hsize\RaggedRight}X}

\begin{document}
% For tables use
\begin{table}
\centering
% table caption is above the table
\caption{Comparison between smartphone and MPU+MCU based monitoring}
\label{swa_tab:2}       % Give a unique label
% For LaTeX tables use
\begin{tabularx}{0.9\linewidth}{L{1}L{1.2}L{0.8}}
    \toprule
\thead{Features} 
    &   \thead{ Smartphone} 
        &   \thead{MCU+MPU}     \\
\midrule
\textbf{Device Type} & General purpose & Dedicated \\
\addlinespace
\textbf{Cost} & High~(US\$100 or more) &  Low~(US\$10 or less)\\
\addlinespace
\textbf{Form Factor} & 6-7 inches & 2-3 inches\\
\addlinespace
\textbf{Power Consumption} & More than 5 watt & less than 1 watt\\
\addlinespace
\textbf{Device Integration} &Very Difficult& Easy to integrate\\
\addlinespace
\textbf{Ease of use}& Difficult for seniors & Easy for seniors\\
\addlinespace
\textbf{Durability \& parts} & Fragile\&costly spare & Durable\&Cheap\\
\noalign{\smallskip}\hline
\end{tabularx}
\end{table}
\end{document}

在此处输入图片描述

(灰线表示文字是边框)

** 附录:**
但是,如果您愿意使用tabularray包来编写表格,那么您的表格代码就会变得相当短:

\documentclass[11pt, la4paper,
                istof=totoc,
                oneside,
                chapterprefix=true,
                sfdefaults=false]{scrbook}
\usepackage[showframe,      % remove this option in the real document
            margin=1in]{geometry}
\usepackage{ragged2e}
\usepackage{tabularray}
\UseTblrLibrary{booktabs}  % it load booktabs packagew ....

\begin{document}
    \begin{table}
\centering
\caption{Comparison between smartphone and MPU+MCU based monitoring}
\label{swa_tab:2}       % Give a unique label
% For LaTeX tables use
\begin{tblr}{width=0.9\linewidth,
             colspec = {X[l, font=\bfseries] X[1.2,l]X[0.8,l]},
             row{1}  = {font=\normalfont} 
            }
    \toprule
Features    &   Smartphone  &   MCU+MPU     \\
    \midrule
\textbf{Device Type} & General purpose & Dedicated \\
\textbf{Cost} & High~(US\$100 or more) &  Low~(US\$10 or less)\\
\textbf{Form Factor} & 6-7 inches & 2-3 inches\\
\textbf{Power Consumption} & More than 5 watt & less than 1 watt\\
\textbf{Device Integration} &Very Difficult& Easy to integrate\\
\textbf{Ease of use}& Difficult for seniors & Easy for seniors\\
\textbf{Durability \& parts} & Fragile\&costly spare & Durable\&Cheap\\
    \bottomrule
\end{tblr}
    \end{table}
\end{document}

在此处输入图片描述

相关内容