1

I am trying to fit a table on the width of a page, but I'm not succeeding. I've tried replicating these posts, but with no luck. I'm quite new to 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}
4
  • The content of the last column of your table is not very wide. So using a column type with line breaks for this column would not help a lot. IMHO you need a column type, that supports line breaks for the second column. But I suggest to use, e.g., X´-columns of package tabularx` as shown in the answers to the other question.
    – cabohah
    Mar 16 at 15:51
  • @cabohah Is this how you mean? \begin{tabularx}{\textwidth}{|X|X|X|}
    – OLGJ
    Mar 16 at 15:59
  • Because that allocates equal size to all the columns, I was hoping to get a larger middle column and as you say put there on two rows if needed.
    – OLGJ
    Mar 16 at 16:02
  • As shown on the answers to the linked question, you don't need to make all columns X-columns. You could, e.g., use lXl. You also could combine X- and p-columns. Whatever you need. You should also read the manual of the package.
    – cabohah
    Mar 16 at 20:16

2 Answers 2

1

Here's a solution that uses a tabularx environment to enable automatic line breaking and automatic hanging indentation in the middle column. To improved visual interest, I suggest adding a bit of vertical whitespace after 4 to 5 rows; the table below has three such visual grouping breaks.

enter image description here

\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}
1

Have a look to the following code:

 \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}

enter image description here

3
  • 1
    Why are you defining 12 columns for a tabular, that uses only 3?
    – cabohah
    Mar 16 at 20:18
  • ups, copy,paste
    – scd
    Mar 16 at 21:47
  • 1
    @scd - Why define 6 columns when 3 are called for?
    – Mico
    Mar 16 at 22:45

Not the answer you're looking for? Browse other questions tagged or ask your own question.