Here is the table I am trying to make:
\documentclass{book}
\usepackage{tabularx, booktabs}
\usepackage{lipsum}
\begin{document}
\begin{table}
\centering
\begin{tabularx}{\textwidth}{lll}
\toprule
Conditions & Items test corrects & Items test incorrects \\
\midrule
Non-adjacents & Fa\textunderscore Sol\textunderscore Ré\textunderscore (O\textunderscore P\textunderscore Q\textunderscore ) & *Do\#\textunderscore Sol\#\textunderscore Si (S\textunderscore R\textunderscore T) \\
& Sol\#\textunderscore Do\#\textunderscore Si\textunderscore (R\textunderscore S\textunderscore T) & *Ré\textunderscore Sol\textunderscore Fa (Q\textunderscore P\textunderscore O) \\
& \textunderscore Do\textunderscore Fa\#\textunderscore Ré\# (\textunderscore u\textunderscore v\textunderscore w) & *La\textunderscore Mi\textunderscore La\# (\textunderscore y\textunderscore x\textunderscore z) \\
& \textunderscore Mi\textunderscore La\textunderscore La\# (\textunderscore x\textunderscore y\textunderscore z) & *Ré\#\textunderscore Fa\#\textunderscore Do (\textunderscore w\textunderscore v\textunderscore u) \\
Adjacents & Ré.Ré\#.Fa.Do.Sol.Fa\# (QwOuPv) & *Si.La.Sol\#.La\#.Do\#.Mi (TyRzSx) \\
& Ré.La\#.Fa.Mi.Sol.La (QzOxPy) & *Si.Fa\#.Sol\#.Ré\#.Do\#.Do (TvRwSu) \\
& Si.Ré\#.Sol\#.Do.Do\#.Fa\# (TwRuSv) & *Ré.La.Fa.La\#.Sol.Mi (QyOzPx) \\
& Si.La\#.Sol\#.Mi.Do\#.La (TzRxSy) & *Ré.Fa\#.Fa.Ré\#.Sol.Do QvOwPu) \\
\bottomrule
\end{tabularx}
\end{table}
\lipsum
\end{document}
The result is as follow:
I tried to reduce the width of my table with \footnotesize
but the text in the table is still a bit beyond the right margin:
Question:
Is there a way to force all the table to stay align with the text with booktabs ?
Best Answer
You don't want
tabularx
, in my opinion.If I try the same with
\begin{tabularx}{lXX}
, I get that one line is split into two rows (with a wrong hyphen, unless I disable hyphenation for the table). A better result is with the specification@{}lXX@{}
:However, the result will change with the text width.
Note that
tabularx
needs at least anX
column in order to work.Note also that
\#
is not the correct symbol for a sharp. I defined\sh
as$\sharp$
(the\sharp
command is only available in math mode, by default).