表格整页宽度调整框的替代方案

表格整页宽度调整框的替代方案

我有几个使用 \csvreader 导入的多列 csv 表。有些比页面宽度小(表 1),有些比页面宽度大(表 2)。我想让它们都正好是整页宽度(6.5 英寸)。Adjustbox 似乎可以缩放文本大小、间距、线宽等,我希望保持这些不变,只需拉伸表格并在列中添加空间即可。如果可能的话,我更希望表 2 中的文本换行,而不是使用较小的字体。

在此处输入图片描述

\documentclass[10pt,letterpaper]{article}               
\usepackage[letterpaper,margin=1in]{geometry}   
\usepackage{fontspec}                   
\usepackage{tabularx}                   
\usepackage{longtable}                  
\usepackage{booktabs}                   
\usepackage{parskip}                    
\usepackage[table]{xcolor}              
\usepackage{sectsty}                    
\usepackage{titlesec}                   
\usepackage{float}                      
\usepackage[font=bf, skip=2pt]{caption}     
\usepackage{fancyhdr}                   
\usepackage{graphicx}                   
\usepackage{csvsimple}                  
\usepackage{adjustbox}                  
\usepackage{datatool}                   
\usepackage[backend=bibtex8]{biblatex}      
\newcommand\myhead[1]{\mbox{\centering\cellcolor{blue}\color{white}\bfseries #1}}   %Table header style         

%Table 1
\usepackage{filecontents}
 \begin{filecontents*}{file1.csv}
Timestamp, Fields, Issue
 xxx,111,222
 333,444,222
 xxx,111,222
 xxx,111,222
 \end{filecontents*}

%Table 2
\usepackage{filecontents}
 \begin{filecontents*}{file2.csv}
Timestamp, Fields, Issue
 xxxxxxxx xxxxxxxxxxxx xxxxxxxx xxxxxxxxx xxxxxx xxxxxx,111111 11111 111111 1111111 1111 1111,222 2222222 22222 2222222 2222222
 333,444,222
 xxx,111,222
 xxx,111,222
 \end{filecontents*}


\begin{document}

%Table 1
\begin{table}[H]
\centering
\caption{\label{tab:screening}Data Periods Removed during Data Quality Assessment}
\csvreader[head to column names, column count=3,respect all, tabular=l|c|c, 
table head=\myhead{Timestamp} & \myhead{Fields} & \myhead{Issue} \\\hline,
  late after first line=\\,
late after line=\\\hline,
  ]%
{file1.csv}{}{%  
\csvcoli & \csvcolii & \csvcoliii}
\end{table}

%Table 2
\begin{table}[H]
\centering
\caption{\label{tab:screening}Data Periods Removed during Data Quality Assessment}
\csvreader[head to column names, column count=3,respect all, tabular=l|c|c, 
table head=\myhead{Timestamp} & \myhead{Fields} & \myhead{Issue} \\\hline,
  late after first line=\\,
late after line=\\\hline,
  ]%
{file2.csv}{}{%  
\csvcoli & \csvcolii & \csvcoliii
}

\end{table}

\end{document}

答案1

我很乐意删除它,但你可以计算距离。

\documentclass[10pt,letterpaper]{article}               
\usepackage[letterpaper,margin=1in,showframe]{geometry}   
\usepackage{fontspec}                   
\usepackage{longtable}                  
\usepackage{booktabs}                   
\usepackage{parskip}                    
\usepackage[table]{xcolor}              
\usepackage[font=bf, skip=2pt]{caption}     
\usepackage{fancyhdr}                   
\usepackage{graphicx}                   
\usepackage{csvsimple}                  
\usepackage{datatool}                   
\usepackage{pgf}                   
\newcommand\myhead[1]{\mbox{\centering\cellcolor{blue}\color{white}\bfseries #1}}   %Table header style         

%Table 1
\usepackage{filecontents}
 \begin{filecontents*}{file1.csv}
Timestamp, Fields, Issue
 xxx,111,222
 333,444,222
 xxx,111,222
 xxx,111,222
 \end{filecontents*}

%Table 2
\begin{filecontents*}{file2.csv}
Timestamp, Fields, Issue
 xxxxxxxx xxxxxxxxxxxx xxxxxxxx xxxxxxxxx xxxxxx xxxxxx,111111 11111 111111 1111111 1111 1111,222 2222222 22222 2222222 2222222
 333,444,222
 xxx,111,222
 xxx,111,222
 \end{filecontents*}

\begin{document}

%Table 1
\begin{table}[htb]
\centering
\caption{\label{tab:screening}Data Periods Removed during Data Quality Assessment}
\csvreader[head to column names, column count=3,respect all, tabular=l|c|c, 
table head=\myhead{Timestamp} & \myhead{Fields} & \myhead{Issue} \\\hline,
  late after first line=\\,
late after line=\\\hline,
  ]%
{file1.csv}{}{%  
\csvcoli & \csvcolii & \csvcoliii}
\end{table}

%Table 2
\begin{table}[htb]
\centering\pgfmathsetmacro{\mywidth}{(\linewidth-6*\tabcolsep)/3}%
\caption{\label{tab:screening2}Data Periods Removed during Data Quality Assessment}
\csvreader[head to column names, column count=3,respect all, 
tabular=p{\mywidth pt}|>{\centering}p{\mywidth pt}|>{\centering\arraybackslash}p{\mywidth pt}, 
table head=\myhead{Timestamp} & \myhead{Fields} & \myhead{Issue} \\\hline,
  late after first line=\\,
late after line=\\\hline,
  ]%
{file2.csv}{}{%  
\csvcoli & \csvcolii & \csvcoliii
}
\end{table}

\end{document}

在此处输入图片描述

showframe仅用于证明其有效。

相关内容