使表格适合页面宽度

使表格适合页面宽度

我试图将表格放入页面宽度内,但没有成功。我尝试复制这些帖子,但没有成功。我对 Latex 还很陌生。

\documentclass{article}
\usepackage{multirow}
\begin{document}
\begin{table}[htp]
\centering
\begin{tabular}{lll|p{5mm}}
\hline
\textbf{Field} & \textbf{Meaning} & \textbf{Type}\\
\hline
lineRef & Reference to the Line in question & ID\\
datedVehicleJourneyRef & Reference to DatedServiceJourney-ID for the corresponding \newline object in the timetable data & ID\\
operatorRef & Reference to Operator in question & ID\\
date & Date of the journey & date \\
originName & Name of the first stop of the departure & String \\
vehicleRef & Reference to the vehicle & ID \\
stopPointRef & Reference to the stop & ID \\
order & The sequential order of the stop & Integer \\
aimedArrivalTime & Originally planned arrival time & dateTime  \\
actualArrivalTime & Actual arrival time & dateTime \\
expectedArrivalTime & Estimated arrival time of the journey according to the prediction & dateTime \\
yhat & The difference between expected and the actual arrival time & Integer \\
timeTableDiff & The difference between the originally planned and the actual arrival time\\

\hline
\end{tabular}
\caption{\label{highres}
The extracted fields from the raw nested JSON data.
}
\end{table}
\end{document}

答案1

这是一个使用tabularx环境来实现中间列的自动换行和自动悬挂缩进的解决方案。为了提高视觉吸引力,我建议在 4 到 5 行后添加一些垂直空白;下表有三个这样的视觉分组分隔符。

在此处输入图片描述

\documentclass{article}
\usepackage{tabularx,ragged2e,booktabs}
% columm type with automatic line breaking and hanging indentation:
\newcolumntype{L}{>{\RaggedRight\hangafter=1\hangindent=1em}X}

\begin{document}

\begin{table}[htbp]
\begin{tabularx}{\textwidth}{@{} l L l @{}}
\toprule
Field & Meaning & Type \\
\midrule
lineRef       & Reference to the Line in question & ID\\
datedVehicleJourneyRef & Reference to DatedServiceJourney-ID 
   for the corresponding object in the timetable data & ID\\
\addlinespace
operatorRef   & Reference to Operator in question & ID\\
date          & Date of the journey & date \\
originName    & Name of the first stop of the departure & String \\
vehicleRef    & Reference to the vehicle & ID \\
\addlinespace
stopPointRef  & Reference to the stop & ID \\
order         & The sequential order of the stop & Integer \\
aimedArrivalTime & Originally planned arrival time & dateTime  \\
actualArrivalTime & Actual arrival time & dateTime \\
\addlinespace
expectedArrivalTime & Estimated arrival time of the journey 
   according to the prediction & dateTime \\
yhat          & The difference between expected and 
   the actual arrival time & Integer \\
timeTableDiff & The difference between the originally planned 
   and the actual arrival time\\
\bottomrule
\end{tabularx}

\caption{The extracted fields from the raw nested JSON data.}
\label{highres}
\end{table}

\end{document}

答案2

看一下下面的代码:

 \documentclass{article}

\usepackage{tabularx}
\usepackage{booktabs}

\begin{document}

\begin{table}[htp]
\begin{tabularx}{\textwidth}{lXl}
\hline
\textbf{Field} & \textbf{Meaning} & \textbf{Type}\\
\hline
lineRef & Reference to the Line in question & ID\\
datedVehicleJourneyRef & Reference to DatedServiceJourney-ID for the corresponding \newline object in the timetable data & ID\\
operatorRef & Reference to Operator in question & ID\\
date & Date of the journey & date \\
originName & Name of the first stop of the departure & String \\
vehicleRef & Reference to the vehicle & ID \\
stopPointRef & Reference to the stop & ID \\
order & The sequential order of the stop & Integer \\
aimedArrivalTime & Originally planned arrival time & dateTime  \\
actualArrivalTime & Actual arrival time & dateTime \\
expectedArrivalTime & Estimated arrival time of the journey according to the prediction & dateTime \\
yhat & The difference between expected and the actual arrival time & Integer \\
timeTableDiff & The difference between the originally planned and the actual arrival time\\

\hline
\end{tabularx}
\caption{\label{highres}
The extracted fields from the raw nested JSON data.
}
\end{table}
\end{document}

在此处输入图片描述

相关内容