0

Given the following table:

\documentclass{standalone}

\usepackage{booktabs, siunitx, multirow}

\begin{document}

    \begin{tabular}{p{1.5cm}lSS}
        \toprule
        & a & x & y \\ \midrule
        \multirow{2}{=}{entdimensionalisiert} & abc & 0,00 & 20,95  \\
        & def & 0,004 & 0,7 \\ \midrule
        \multirow{2}{=}{normalisiert} & abc & 0,00& 20,95  \\
        & def & 1,00 & 175,00 \\ \bottomrule
    \end{tabular}   

\end{document}

How can I pass the width of the p-column to both multirows, so that the text inside each multirow can have automatic line breaks accordingly? Instead of *as width information tried =, yet of no avail.

3
  • 3
    the first word of a paragraph does not hyphenate by default so there would be no line breaking whatever width was passed in unless you put \hspace*{0pt} to allow hyphenation. Commented Dec 31, 2021 at 16:23
  • Ok, thanks for the information, I will try my luck with your solution and will give feedback once I tried it.
    – Lukas
    Commented Dec 31, 2021 at 17:20
  • I tried the starred hspace in different positions, but unfortunately with no different result than without it. So the words still didn't hyphenate even with the multirow width set to 0pt
    – Lukas
    Commented Jan 1, 2022 at 17:40

2 Answers 2

1

Edit: Now is considered OP comments. Added is solution which use LuaLaTeX engine for compiling MWE. It enables to hyphenate also the first word in cell's content.

Use of the siunitx package for S columns can be simple as you use in your MWE: just S without any options anticipate writing a simple numbers with default number of integer and decimal digits in number. However package is much more powerful. It enable to specify (as options) number of integers and decimals: table-format=<number of integer digits>.<number of decimal digits> (an elementary option), numbers rounding, adding symbols, etc. For details see package documentation. It is illustrated with many examples.

Use of \multirow{2}{=}{...} is right way, however you MWE compiling by pdfLaTeX doesn't support hyphenation of the first word in cells' text. Problem you can solve on two ways:

  • by inserting of hyphenation points \- in words as is done in in the following MWE:
\documentclass[margin=2mm]{standalone}

\usepackage{booktabs, multirow}
\usepackage{siunitx}

\begin{document}
    \begin{tabular}{ p{19mm} l S[table-format=1.3] S[table-format=3.2] }
        \toprule
        & a & {x} & {y} \\ \midrule
\multirow{2}{=}{entdimen\-sionalisiert} 
        & abc & 0,00 & 20,95  \\
        & def & 0,004 & 0,7 \\ \midrule
\multirow{2}{=}{normalisiert} 
        & abc & 0,00& 20,95  \\
        & def & 1,00 & 175,00 \\ \bottomrule
    \end{tabular}
\end{document}

enter image description here

  • or by adding package babel to the MWE and than compile by LuaLaTeX:
\documentclass[margin=2mm]{standalone}
\usepackage[ngerman]{babel}   % <---

\usepackage{booktabs, multirow}
\usepackage{siunitx}

\begin{document}
    \begin{tabular}{ p{17mm} l S[table-format=1.3] S[table-format=3.2] }
        \toprule
        & a & {x} & {y} \\ \midrule
\multirow{2}{=}{entdimensionalisiert}
        & abc & 0,00 & 20,95  \\
        & def & 0,004 & 0,7 \\ \midrule
\multirow{2}{=}{normalisiert}
        & abc & 0,00& 20,95  \\
        & def & 1,00 & 175,00 \\ \bottomrule
    \end{tabular}
\end{document}

enter image description here

4
  • I read here that switching from PDFLaTeX to LuaLaTeX allows the hyphenation of first words in paragraphs and gave it a try. With this I could reproduce your results. In addition you don't even have to specify hyphenation points (to have correct hyphenation points I added the babel package with the ngerman option), then the result was as desired/what I was looking for. Maybe you want to add these suggestions to your answer, then I could mark it as the correct one.
    – Lukas
    Commented Jan 2, 2022 at 8:56
  • @Lukas, thank you for comment. Fone!
    – Zarko
    Commented Jan 2, 2022 at 9:39
  • You're welcome. If you don't mind, could you elaborate why you specified the S-type columns and what this definitions (table-format 1.3 and table format 3.2) mean, I tried to understand the siunitx-documentation but couldn't figure it out by myself unfortunately.
    – Lukas
    Commented Jan 2, 2022 at 9:58
  • 1
    @Lukas, see edited answer. Added is short note about siunitx.
    – Zarko
    Commented Jan 2, 2022 at 10:28
1

Here is a solution using the new tabularray package (CTAN).

\documentclass{article}

\usepackage{booktabs, siunitx}
\usepackage{tabularray}
\UseTblrLibrary{booktabs, siunitx}

\begin{document}

\begin{tblr}{p{1.7cm}lSS}
    \toprule
    & a & x & y \\ \cmidrule{2-4}
    \SetCell[r=2]{t} entdimensionalisiert & abc & 0,00 & 20,95  \\
    & def & 0,004 & 0,7 \\ \midrule
    \SetCell[r=2]{t} normalisiert & abc & 0,00& 20,95  \\
    & def & 1,00 & 175,00 \\ \bottomrule
\end{tblr} 
    
\end{document}

output table

I have increased the width to 1.7cm, because the text "entdimensionalisert" would otherwise span 3 lines.

The tabularray equivalent of \multirow{2} is \SetCell[r=2]. The width is automatically taken from the table columns definition.

Note

This has to be compiled with LuaLaTex to allow hyphenation of the first word in a paragraph.

3
  • unfortunately when I copy your MWE both words are not hyphanated and span a single line each (and are written beyond the cells to their respective right)
    – Lukas
    Commented Jan 2, 2022 at 8:47
  • I read here that switching from PDFLaTeX to LuaLaTeX allows the hyphenation of first words in paragraphs and gave it a try. With this I could reproduce your results.
    – Lukas
    Commented Jan 2, 2022 at 8:53
  • That's right, I compiled this with LuaLaTeX. Did not know, that it makes a difference with hyphenation.
    – marv
    Commented Jan 2, 2022 at 8:55

You must log in to answer this question.

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