1

I'm trying to reproduce this kind of table

enter image description here

Here is my attempt

\documentclass[10pt,a4paper]{toptesi}
\usepackage[utf8]{inputenc}
\usepackage[italian]{babel}
\usepackage{booktabs}
\usepackage{tabularx}
\begin{tabularx}{\textwidth}{l l | l}
\toprule
\multicolumn{2}{l}{Nome}                            & Descrizione \\
\midrule
String                  & getName()                 & ottiene il nome della classe \\
int                         & getModifiers()            & ottiene il modifiers\\
\bottomrule
\end{tabularx}
\end{document}

and that's the result

enter image description here

First I need the tabular to fill the entire width page, but the main problem is that the two columns aren't occupying the 50% of the page width and I'm not able to get rid of this badbox error

Overfull \hbox (15.0pt too wide) in paragraph at lines 28--29

which is referring to the \end{tabularx} line

3
  • 1
    I would guess that you have a 15pt paragraph indentation prefix the tabularx with \noindent (please always use complete examples that can be tested, not just fragments) Commented Jul 11, 2018 at 21:46
  • 2
    also every tabularx needs at least one X column, but you have three l columns. Commented Jul 11, 2018 at 21:47
  • I've edited the post. Could you please correct my code? Commented Jul 11, 2018 at 21:58

2 Answers 2

2

The code as posted produces the error

! Undefined control sequence.
\@BTswitch ->{\CT@arc@ 

as you have no \begin{document}

The

Overfull \hbox (15.0pt too wide) in paragraph at lines 16--17

is paragraph indentation

and

Underfull \hbox (badness 10000) in alignment at lines 16--16
[][][] 

is because you have stretched the table but provided no way to fill the space so the line is underfull

so:

\documentclass[10pt,a4paper]{toptesi}
\usepackage[utf8]{inputenc}
\usepackage[italian]{babel}
\usepackage{booktabs}

\usepackage{tabularx}

\begin{document}
\begin{center}

\begin{tabularx}{\textwidth}{l l | X}
\toprule
\multicolumn{2}{l}{Nome}                            & Descrizione \\
\midrule
String                  & getName()                 & ottiene il nome della classe \\
int                         & getModifiers()            & ottiene il modifiers\\
\bottomrule
\end{tabularx}

\end{center}

\end{document}
2
  • How to set the two main columns to occupy the 50% of the page width? Commented Jul 11, 2018 at 22:07
  • 1
    stretching the table out would make it very hard to read, moving the type away from the method name. but if you really want that you could replace the two l l by p{.25\textwidth} p{.25\textwidth} @AntonioSantoro Commented Jul 11, 2018 at 22:14
0

The overfull by 15pt is the indentation (you wouldn't get it if the table is inside a table environment).

If you want that the first two column together occupy half of the text width and the same for the third column, you can use tabular*:

\documentclass[10pt,a4paper]{toptesi}
\usepackage[utf8]{inputenc}
\usepackage[italian]{babel}
\usepackage{booktabs}
\usepackage{tabularx}

\begin{document}

\noindent
\begin{tabular*}{\textwidth}{
  @{}
  l
  l
  @{\extracolsep{\fill}}
  p{0.5\textwidth}
  @{}
}
\toprule
\multicolumn{2}{@{}l}{Nome}                            & Descrizione \\
\midrule
String                  & getName()                 & ottiene il nome della classe \\
int                         & getModifiers()            & ottiene il modifiers\\
\bottomrule
\end{tabular*}

\end{document}

enter image description here

However the result is not that pretty. The vertical rule does nothing, so it's better to omit it.

Note that “il modifiers” is wrong and should perhaps be “i modifier” (foreign words in Italian are not inflected).

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .