Tabularx does not work anymore

tablestabularx

I’ve always used tabularx without any problem, but now out of nothing it doesn’t make \textwidth anymore and I don't understand why (last time I opened my document, everything was fine). Could you tell me please what’s the problem?

\documentclass[a4paper, 11pt, pointlessnumbers, xcolor=dvipsnames]{scrreprt}

\usepackage[utf8]{inputenc}
\usepackage[french]{babel}
\usepackage[T1]{fontenc}
\usepackage{latexsym}
\usepackage{tabularx}
\usepackage{ltablex}
\usepackage{amssymb}
\usepackage{booktabs}

\babeltags{ger=ngerman}

\usepackage{array, booktabs, boldline}

\begin{document}
\noindent
\def\arraystretch{1.5}
\begin{tabularx}{\textwidth}{>{\raggedright\arraybackslash}p{2.5cm}>{\raggedright\arraybackslash}X>{\raggedright\arraybackslash}X>{\raggedright\arraybackslash}X}
\hlineB{2}
\textsf{\textbf{Addition}} & Avant tout & Ensuite & Pour conclure \\
\hlineB{2}
\end{tabularx}

\end{document}

Best Answer

  • Your document example can be compile without any error or warnins, i.e. it works as expected

  • You should be aware, that ltablex has a features that in cases, when contents in columns are shorter as would be at X column when only tabularx is loaded, reduce their width to natural width of columns contents (what happens in your case).

  • Your problems can be solved on two ways:

    • from preamble remove the ltablex package and use some other package which combine longtable and tabularx, for example xltabular
    • if for some reason you need to use ltablex, than add \keepXColumns to document preamble:
\documentclass[a4paper, 11pt, pointlessnumbers, xcolor=dvipsnames]{scrreprt}
%---------------- Show page layout. Don't use in a real document!
\usepackage{showframe}
\renewcommand\ShowFrameLinethickness{0.15pt}
\renewcommand*\ShowFrameColor{\color{red}}
%---------------------------------------------------------------%
\usepackage[french]{babel}
\usepackage[T1]{fontenc}
\usepackage{amssymb, latexsym}
\usepackage{boldline, ltablex}
\newcolumntype{L}{ >{\raggedright\arraybackslash}X}
\keepXColumns

\babeltags{ger=ngerman}


\begin{document}
\noindent
\def\arraystretch{1.5}
\begin{tabularx}{\textwidth}{>{\raggedright\arraybackslash}p{2.5cm}
                             LLL}
\hlineB{2}
\textsf{\textbf{Addition}} & Avant tout & Ensuite & Pour conclure \\
\hlineB{2}
\end{tabularx}

\end{document}

enter image description here

(red lines indicate text borders)

Related Question