1

I'm in the Latex tabular environment. I want to align the text in a multicolumn to the left, but it does not work. It is always alignt to the right.

Here is my code:

\begin{tabular}{|p{2cm}|p{2cm}|p{2cm}|p{2cm}|p{2cm}|}\hline
\textbf{number of lanes:} & \multicolumn{2}{l|}\textbf{8 (20 m width)} & \multicolumn{2}{l|} \textbf{10 (25 m width)}\\
  & distance & free space loss & distance & free space loss \\\hline 
\textbf{lane length 25 m} & 16.008 m & 10 dB & 17.678 m & 30 dB\\\hline
\textbf{lane length 50 m} & 26.926 m & 20 dB & 27.951 m & 40 dB\\\hline
\end{tabular}

and the output is always:

table output

Waht I'm doing wrong?

I'm on Kubuntu 20.10 with Kile kile 2.9.93

OS: Kubuntu 20.10 KDE-Plasma-Version: 5.19.5 KDE-Frameworks-Version: 5.74.0 Qt-Version: 5.14.2 Kernel-Version: 5.8.0-63-generic Architecture: 64-bit Prozessors: 4 × Intel® Core™ i5-3320M CPU @ 2.60GHz RAM: 7,6 GiB GPU: Mesa DRI Intel® HD Graphics 4000

(If you ask, it's for a vital parameters telemetry radio system for swimmers)

3
  • Welcome to TeX.SE! Can you please make your code snippet be compilable, then we do not have to guess what you are doing ...
    – Mensch
    Oct 25, 2021 at 14:28
  • Did you try using \multicolumn{cols}{pos}{text} correctly? It looks like your text ist not in bracktes.
    – mais
    Oct 25, 2021 at 14:34
  • Thanks, this will work Oct 25, 2021 at 14:40

2 Answers 2

2

You may give a chance to tabularray and siunitx (loaded as tabularray library) packages. Using them you will get simple control on cells contents aligning and writing units. For details of all possibilities of those two powerful packages are thoroughly described in theirs documentation.

  • a case, when all cells contents is left aligned:
\documentclass{article}
\usepackage{tabularray}
\UseTblrLibrary{siunitx}

\begin{document}
    \begin{table}[ht]
    \centering
    \sisetup{text-series-to-math}
\begin{tblr}{hline{1,3-Z}, vlines,
             colspec = {*{5}{X[l,m]}}, 
             column{1} = {font=\bfseries},
             row{1} = {font=\bfseries}
             }
number of lanes:
    &   \SetCell[c=2]{l} 8 (\qty{20}{m} width)
        &   &   \SetCell[c=2]{l} 10 (\qty{25}{m} width)    
                &                       \\
    &   distance 
        &   free space loss 
            &   distance 
                &   free space loss     \\
lane length \qty[unit-font-command=\mathbf]{25}{m} 
    & \qty{16.008}{m} 
        &   \qty{10}{dB} 
            &   \qty{17.678}{m} 
                &   \qty{30}{dB}        \\
lane length \qty[unit-font-command=\mathbf]{50}{m} 
    &   \qty{26.926}{m} 
        &   \qty{20}{dB} 
            &   \qty{27.951}{m} 
                &   \qty{40}{dB}        \\
\end{tblr}
    \end{table}
\end{document}

enter image description here

  • a case, where except first one a cells contents are centered. In this case the table specification in above MWE is changed to:
\begin{tblr}{hline{1,3-Z}, vlines,
             colspec = {X[l,m]*{4}{X[c,m]}},    % <---
             column{1} = {font=\bfseries},
             row{1} = {font=\bfseries}
             }

and multi column cells specification to:

\SetCell[c=2]{c}

which gives:

enter image description here

Edit:

  • one more possible table layout:

enter image description here

which you can get with the following table preamble:

\begin{tblr}{hlines, vlines,
             colspec = {X[l,m]*{4}{X[c,m]}},    
             column{1} = {font=\bfseries},
             row{1} = {font=\bfseries}
             }
1

You forgot braces {} around the text of the \multicolumn. I also added \raggedright to get a nicer layout. I did this by defining a new column type q.

\documentclass{article}
\usepackage{array}
\newcolumntype{q}[1]{>{\raggedright\arraybackslash}p{#1}}
\begin{document}
\begin{tabular}{|q{2cm}|q{2cm}|q{2cm}|q{2cm}|q{2cm}|}\hline
\textbf{number of lanes:} & \multicolumn{2}{l|}{\textbf{8 (20 m width)}} & \multicolumn{2}{l|} {\textbf{10 (25 m width)}}\\
  & distance & free space loss & distance & free space loss \\\hline 
\textbf{lane length 25 m} & 16.008 m & 10 dB & 17.678 m & 30 dB\\\hline
\textbf{lane length 50 m} & 26.926 m & 20 dB & 27.951 m & 40 dB\\\hline
\end{tabular}
\end{document}

enter image description here

1

You must log in to answer this question.

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