如何将表格的宽度调整为Latex中的页面/文本宽度?

问题描述 投票:0回答:1

我正在尝试将表格的宽度强制为页面/文本的宽度。我尝试使用\resizebox{\textwidth}{!},但在这种情况下我不确定如何应用此功能(resizebox适用于我正在制作的同一张纸中的另一张表)。这是代码:

\documentclass[12pt,a4paper]{article}
\usepackage[top=2cm, bottom=2cm, left=5cm, right=2cm]{geometry}
\usepackage{setspace}
\singlespacing
\usepackage{lettrine}
\usepackage{lmodern}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage{biblatex}
\usepackage{titling}
\usepackage{graphicx}
\usepackage{tabularx,booktabs}
\setlength{\droptitle}{-4em}

\begin{document}

\newcommand{\btable}[3]{
\begin{table}[htbp]
\begin{center}
\caption{#2\label{#3}}
\begin{tabular}{#1}}
\newcommand{\etable}{\end{tabular}
\end{center}
\end{table}}
%Usage: \mc{number of columns spanned}{major column heading}
\newcommand{\mc}[2]{\multicolumn{#1}{c}{#2}}
\btable{l|ccccccccccc}{Sensitivity analysis}{results} \hline\hline
%6 fields, justified left, center x 5
%double horizontal line at top, 1 vertical bar
& \mc{3}{Excluding 1 name} & & \mc{3}{Excluding 2 name} & & \mc{3}{Excluding 3 name} \\ 
\cline{2-4} \cline{6-8} \cline{10-12} 
& Eq.1 & Eq.2 & Eq.3 & & Eq.1 & Eq.2 & Eq.3 & & Eq.1 & Eq.2 & Eq.3\\ \hline
Median & -0.08 & -0.08 & -0.09 & & -0.08 & -0.08 & -0.09 & & -0.08 & -0.08 & -0.09\\
Mean & -0.079 & -0.079 & -0.087 & & -0.083 & -0.082 & -0.090 & & -0.077 & -0.077 & -0.084\\
Min & -0.06 & -0.06 & -0.07 & & -0.05 & -0.05 & -0.06 & & -0.05 & -0.05 & -0.06\\
Max & -0.09 & -0.09 & -0.10 & & -0.10 & -0.10 & -0.11 & & -0.10 & -0.10 & -0.11\\
Spread & -0.03 & -0.03 & -0.03 & & -0.05 & -0.05 & -0.05 & & -0.05 & -0.05 & -0.05\\
Std & 0.88\% & 0.79\% & 0.86\% & & 1.42\% & 1.39\% & 1.21\% & & 1.60\% & 1.60\% & 1.42\% \\ \hline 
\etable 

\end{document}
latex latex-environment
1个回答
0
投票

我做到了:)

\begin{table}
\caption{Sensitivity analysis}
\resizebox{\textwidth}{!}{%
  \begin{tabular}{l|ccccccccccc}
\hline \hline 
& \mc{3}{Excluding 1 name} & & \mc{3}{Excluding 2 name} & & \mc{3}{Excluding 3 name} \\ 
\cline{2-4} \cline{6-8} \cline{10-12} 
& Eq.1 & Eq.2 & Eq.3 & & Eq.1 & Eq.2 & Eq.3 & & Eq.1 & Eq.2 & Eq.3\\ \hline
Median & -0.08 & -0.08 & -0.09 & & -0.08 & -0.08 & -0.09 & & -0.08 & -0.08 & -0.09\\
Mean & -0.079 & -0.079 & -0.087 & & -0.083 & -0.082 & -0.090 & & -0.077 & -0.077 & -0.084\\
Min & -0.06 & -0.06 & -0.07 & & -0.05 & -0.05 & -0.06 & & -0.05 & -0.05 & -0.06\\
Max & -0.09 & -0.09 & -0.10 & & -0.10 & -0.10 & -0.11 & & -0.10 & -0.10 & -0.11\\
Spread & -0.03 & -0.03 & -0.03 & & -0.05 & -0.05 & -0.05 & & -0.05 & -0.05 & -0.05\\
Std & 0.88\% & 0.79\% & 0.86\% & & 1.42\% & 1.39\% & 1.21\% & & 1.60\% & 1.60\% & 1.42\% \\ \hline 
  \end{tabular}}
\end{table}
© www.soinside.com 2019 - 2024. All rights reserved.