4

I have a xltabular table which is filled via script with data, so I don't really know what length the text has that is put into the table cells. Is there a function or method which can just cut off the text if it is too long to fit in one line? Here is the example of my table.

\documentclass[
fontsize=11pt,
parskip=half,
firstfoot=off,
foldmarks=off
]{scrlttr2}  
%

\usepackage[T1]{fontenc} \usepackage[ngerman]{babel} \usepackage{lmodern}

\usepackage{xltabular} \usepackage[textwidth=\useplength{firstfootwidth}]{geometry} %showframe

\renewcommand*\familydefault{\sfdefault}

\begin{document}

%recipient
\begin{letter}{ Max Muste \ Teststraße 2 \ 55555 Teststadt \ Schweiz \ } % \opening{} %

{\footnotesize \begin{xltabular}{\textwidth}{@{\hskip0pt}r p{3.1cm} X r r r@{\hskip0pt}}

Menge & Artikelnummer & Bezeichnung & WHG & Einzelpreis & Gesamtpreis \ \hline \endfirsthead

Menge & Artikelnummer & Bezeichnung & WHG & Einzelpreis & Gesamtpreis \ \hline \endhead \hline \multicolumn{6}{l}{Bla} \endlastfoot 1 & T-ERICSSON GF768 & Lötzinn bleifrei mit Silber- und Kupferanteil,Ø 1,0 mm, 12,5 g & 0 N & 12,77300 & 12,77\ *[\fill] \end{xltabular} }

\end{letter} \end{document}

enter image description here

So basically mm, 12,5g should be thrown away, even if it is as text in the cell.

Namal
  • 301
  • Shouldn't ",Ø 1,0 mm, 12,5 g" be discarded? The substring ",Ø 1,0", by itself, must surely cause needless confusion. – Mico Feb 15 '22 at 08:37
  • @Mico Yes, it will be confusing and outright stupid. But I just want to know if it is possible. The word wrap in itself with the full information is flawless, but I just want to know if it is possible. – Namal Feb 15 '22 at 08:41
  • the only thing tabularx does compared to a normal table is adjust the target width for linebreaking in X cells, I would never use tabularx for data tables that do not need linebreaking (even though I wrote it) – David Carlisle Feb 15 '22 at 08:46
  • 1
    Maybe https://tex.stackexchange.com/questions/557188/cutting-text-to-a-given-length? – Rmano Feb 15 '22 at 08:59

1 Answers1

4

Well, there is not much sense to use an X column if you want to do that, an l ones will work ok, but one option is to use the truncate package (although you need a bit of gimmick to automatically apply it to a cell, here I use collcell package):

\documentclass[
fontsize=11pt,
parskip=half,
firstfoot=off,
foldmarks=off
]{scrlttr2}
%

\usepackage[T1]{fontenc} \usepackage[ngerman]{babel} \usepackage{lmodern}

\usepackage{xltabular} \usepackage[textwidth=\useplength{firstfootwidth}]{geometry} %showframe \usepackage[fit, hyphenate]{truncate} \usepackage{collcell} \def\mytruncate{\truncate{6cm}} \newcolumntype{T}{ >{\collectcell\mytruncate}X<{\endcollectcell} }

\renewcommand*\familydefault{\sfdefault} \begin{document}

%recipient \begin{letter}{ Max Muste \ Teststraße 2 \ 55555 Teststadt \ Schweiz \ } % \opening{}

% {\footnotesize \begin{xltabular}{\textwidth}{@{\hskip0pt}r p{3.1cm} T r r r@{\hskip0pt}}

Menge & Artikelnummer & Bezeichnung & WHG & Einzelpreis & Gesamtpreis \ \hline \endfirsthead

Menge & Artikelnummer & Bezeichnung & WHG & Einzelpreis & Gesamtpreis \ \hline \endhead \hline \multicolumn{6}{l}{Bla} \endlastfoot 1 & T-ERICSSON GF768 & Lötzinn bleifrei mit Silber- und Kupferanteil,Ø 1,0 mm, 12,5 g & 0 N & 12,77300 & 12,77\ *[\fill] \end{xltabular} }

\end{letter} \end{document}

enter image description here

Rmano
  • 40,848
  • 3
  • 64
  • 125
  • Thx @Rmano, how can I redifine the Marker if I just want a whitespace? I tried it according to the doc with \TruncateMarker(\renewcommand{\TruncateMarker}{}) but I get an error. – Namal Feb 15 '22 at 09:26
  • 2
    It's \renewcommand\TruncateMarker{~}, I suppose – Rmano Feb 15 '22 at 09:26