graphicx 用表格产生错误

graphicx 用表格产生错误

graphicx当我使用该包和从此网站生成的表时出现编译错误:https://www.tablesgenerator.com/。当我从文本中删除\usepackage{graphicx}并离开表格时,编译工作正常。另一方面,当我从表格中移除并离开时\usepackage{graphicx},编译工作也正常。我需要它们两者一起工作。以下是我正在处理的文本示例:

\documentclass{article}
\renewcommand{\contentsname}{Sumário}
\usepackage[utf8]{inputenc}
\usepackage{setspace}
\onehalfspacing
\usepackage{hyperref}
\hypersetup{colorlinks=true,linkcolor=[rgb]{0,0,0.6},citecolor=[rgb]{0,0,0.6},urlcolor=[rgb]{0,0,0.6}}
\usepackage[T1]{fontenc}
\usepackage{geometry}
\geometry{verbose,tmargin=2.5cm,bmargin=2.5cm,lmargin=2.5cm,rmargin=2.5cm}
\usepackage{mathpazo}
\renewcommand{\sfdefault}{lmss}
\renewcommand{\ttdefault}{lmtt}
\usepackage{graphicx}


\title{Regulation}
\author{Mateus Maciel}

\begin{document}

\maketitle

\section{Introduction}

\begin{table}[]
\centering
\resizebox{\textwidth}{}{%
\begin{tabular}{cccc}
\textbf{Variable}                            & \textbf{Granularity}              & \textbf{Period} & \textbf{Source} \\ \hline
Mobile broadband connections (3G and 4G)     & Municipality                      & 2007-2021       & Teleco          \\
Regulation Index                             & 100 most populated municipalities & 2016-2022       & Teleco          \\
Investment (number of antennas per provider) & Municipality                      & 1998-2022       & ANATEL          \\
Quality (internet speed)                     & Municipality                      & 2014-2022       & Ookla           \\
Population                                   & Municipality                      & 1991-2021       & IBGE            \\
GDP                                          & Municipality                      & 1999-2019       & IBGE            \\
Employment                                   & Municipality                      & 1985-2020       & IBGE            \\ \hline
\end{tabular}%
}
\caption{Summary of the dataset}
\label{tab:my-table}
\end{table}

\end{document}

答案1

不要用于\resizebox包含文本的元素。这通常会导致非常糟糕的结果。

相反,你可以使用如下表格:

\documentclass{article}
\renewcommand{\contentsname}{Sumário}
\usepackage[utf8]{inputenc}
\usepackage{setspace}
\onehalfspacing
\usepackage{hyperref}
\hypersetup{colorlinks=true,linkcolor=[rgb]{0,0,0.6},citecolor=[rgb]{0,0,0.6},urlcolor=[rgb]{0,0,0.6}}
\usepackage[T1]{fontenc}
\usepackage{geometry}
\geometry{verbose,tmargin=2.5cm,bmargin=2.5cm,lmargin=2.5cm,rmargin=2.5cm}
\usepackage{mathpazo}
\renewcommand{\sfdefault}{lmss}
\renewcommand{\ttdefault}{lmtt}
\usepackage{graphicx}


\title{Regulation}
\author{Mateus Maciel}
\usepackage{tabularx}
\usepackage{booktabs}

\begin{document}

\maketitle

\section{Introduction}

\begin{table}[htbp]
\begin{tabularx}{\linewidth}{@{}X>{\raggedright}p{3.5cm}ll@{}}
\toprule
\textbf{Variable}                            & \textbf{Granularity}              & \textbf{Period} & \textbf{Source} \\ \midrule
Mobile broadband connections (3G and 4G)     & Municipality                      & 2007-2021       & Teleco          \\
Regulation Index                             & 100 most populated municipalities & 2016-2022       & Teleco          \\
Investment (number of antennas per provider) & Municipality                      & 1998-2022       & ANATEL          \\
Quality (internet speed)                     & Municipality                      & 2014-2022       & Ookla           \\
Population                                   & Municipality                      & 1991-2021       & IBGE            \\
GDP                                          & Municipality                      & 1999-2019       & IBGE            \\
Employment                                   & Municipality                      & 1985-2020       & IBGE            \\ \bottomrule
\end{tabularx}%
\caption{Summary of the dataset}
\label{tab:my-table}
\end{table}

\end{document}

在此处输入图片描述

相关内容