La colonna della tabella non si adatta
Sto usando il pacchetto tabularx e come da risposta precedente questo dovrebbe essere ordinato in base al problema di avere una tabella in cui le righe sono troppo larghe. La mia comprensione era che questo avrebbe avvolto i testi e si sarebbe adattato. Ma in realtà questo sta andando oltre la larghezza della pagina.
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{array}
\usepackage{wrapfig}
\usepackage{multirow}
\usepackage{tabularx}% for 'tabularx' env. and 'X' col. type
\usepackage{lscape}
\usepackage{listings}
\usepackage{color}
\usepackage{xparse}
\usepackage{placeins}
\usepackage{caption}
\usepackage{enumitem}
\usepackage{booktabs} % for \toprule, \midrule etc macros
\usepackage{ragged2e} % for \RaggedRight macro
\title{examle}
\author{An example from Overleaf}
\begin{document}
\maketitle
\renewcommand{\arraystretch}{1.3}
\listoftables
%% create a derivative column type called 'L':
\newcolumntype{L}{>{\RaggedRight\hangafter=1\hangindent=1.5em}X}
\vspace{1cm}
% \newcolumntype{b}{X}
% \newcolumntype{s}{>{\hsize=.5\hsize}X}
\begin{table*}
\caption{example}
\label{tab:code-example}
\centering
% \begin{tabularx}{\textwidth}{XX}
\begin{tabularx}{1.0\textwidth}{XX}
\toprule % replaced all \hline commands with rules from the booktabs package
\upshape Representation of the code & Code \\
\midrule
Representation 1
& \verb|ID math . ID1 calculateSomethingAwesome ( LIT 100 , LIT 200, LIT 300 )| \\
Another representation name that can be very very long
& \verb|ID math . ID1 calculateSomethingAwesome ( LIT 100 , INTEGER 200, LIT 300 )| \\
Representation 3
& \verb|ID math . ID1 calculateSomethingAwesome ( FLOAT 100 , NUMERIC 200, LIT ID 300 )| \\
\bottomrule
\end{tabularx}
\end{table*}
\end{document}
Risposte
Il testo letterale è troppo lungo per poter essere inserito nella tabella. Potrei essere una soluzione che invece \verb
usi \ttfamily
font e abiliti, quel testo nella seconda colonna cab essere spezzato in più righe .:

\documentclass{article}
\usepackage{ragged2e}
\usepackage{booktabs, tabularx}
\newcolumntype{L}{>{\RaggedRight\hangafter=1\hangindent=1em}X}
\begin{document}
\listoftables
\begin{table}[ht]
\caption{example}
\label{tab:code-example}
\centering
\renewcommand{\arraystretch}{1.3}
\begin{tabularx}{\textwidth}{@{}>{\hsize=0.8\hsize}L
>{\hsize=1.2\hsize\ttfamily}L
@{}}
\toprule %
Representation of the code & Code \\
\midrule
Representation 1
& ID math.ID1 calculateSomethingAwesome (LIT 100, LIT 200, LIT 300)\\
Another representation name that can be very very long
& ID math.ID1 calculateSomethingAwesome (LIT 100, INTEGER 200, LIT 300) \\
Representation 3
& ID math.ID1 calculateSomethingAwesome (FLOAT 100, NUMERIC 200, LIT ID 300)\\
\bottomrule
\end{tabularx}
\end{table}
\end{document}
Se dai un'occhiata più da vicino agli avvisi che ricevi compilando il tuo documento, puoi trovare
\verb may be unreliable inside tabularx
Questo dà già un suggerimento sul motivo per cui la tua tabella trabocca ancora nei margini, sebbene tu abbia usato tabularx
. Per ovviare a questo, puoi utilizzare \lstinline
in combinazione con l' breaklines=true
opzione del listings
pacchetto, che hai già caricato nel tuo preambolo. Il carattere utilizzato per il codice può ovviamente essere regolato utilizzando le opzioni appropriate all'interno di \lstset
.
Il seguente MWE contiene due diverse versioni della tua tabella, una che utilizza tabularx
, l'altra una normale tabular
con p
colonne di tipo. Entrambi sono larghi quanto la larghezza del testo. Nell'esempio, ho anche commentato i pacchetti non necessari e aggiunto una spiegazione del motivo per cui ho rimosso ogni pacchetto.

\documentclass{article}
%\usepackage[utf8]{inputenc} not needed since this is the default with an up-to-date installation
%\usepackage{array} not needed since internally loaded by tabularx
\usepackage{wrapfig}
\usepackage{multirow}
\usepackage{tabularx}
%\usepackage{array,booktabs} Do not load packages more than once.
\usepackage{lscape}
\usepackage{listings}
%\usepackage{color} better to use xcolor instead
%\usepackage{tabularx} Do not load packages more than once.
%\usepackage{multirow} Do not load packages more than once.
%\usepackage{lscape} Do not load packages more than once.
\usepackage{xparse}
\usepackage{placeins}
\usepackage{caption}
\usepackage{enumitem}
%\usepackage{array} Do not load packages more than once.
%\usepackage{wrapfig} Do not load packages more than once.
%\usepackage{booktabs} Do not load packages more than once.
%\usepackage{tabularx} Do not load packages more than once.
\usepackage{ragged2e} % for \RaggedRight macro
\usepackage{booktabs}
\lstset{breaklines=true}
\title{ContextML Tables For the ICSE Submission}
\author{An example from Overleaf}
\begin{document}
\maketitle
\renewcommand{\arraystretch}{1.3}
\listoftables
\begin{table}
\caption{example}
\label{tab:code-example}
\centering
\begin{tabularx}{1.0\textwidth}{XX}
\toprule % replaced all \hline commands with rules from the booktabs package
\upshape Representation of the code & Code \\
\midrule
Representation 1
& {\lstinline|ID math . ID1 calculateSomethingAwesome ( LIT 100 , LIT 200, LIT 300 )|} \\
Another representation name that can be very very long
& {\lstinline|ID math . ID1 calculateSomethingAwesome ( LIT 100 , INTEGER 200, LIT 300 )|} \\
Representation 3
& {\lstinline|ID math . ID1 calculateSomethingAwesome ( FLOAT 100 , NUMERIC 200, LIT ID 300 )|} \\
\bottomrule
\end{tabularx}
\end{table}
\begin{table}
\caption{example}
\label{tab:code-example}
\centering
\begin{tabular}{>{\raggedright\arraybackslash}p{\dimexpr0.35\linewidth-2\tabcolsep}
>{\raggedright\arraybackslash}p{\dimexpr0.65\linewidth-2\tabcolsep}}
\toprule % replaced all \hline commands with rules from the booktabs package
\upshape Representation of the code & Code \\
\midrule
Representation 1
& {\lstinline|ID math . ID1 calculateSomethingAwesome ( LIT 100 , LIT 200, LIT 300 )|} \\
Another representation name that can be very very long
& {\lstinline|ID math . ID1 calculateSomethingAwesome ( LIT 100 , INTEGER 200, LIT 300 )|} \\
Representation 3
& {\lstinline|ID math . ID1 calculateSomethingAwesome ( FLOAT 100 , NUMERIC 200, LIT ID 300 )|} \\
\bottomrule
\end{tabular}
\end{table}
\end{document}