1

I doesn't get my code fixed by the width. Latex says that I use illegal character in the array. This is my code:

\begin{table}[ht!]
\centering
\begin{tabular}{|| c{5cm} | c{5cm} | c{5cm} | c{5cm} | c{5cm} ||}
 \hline
 Buis & Lengte (m) & Debiet (m\textsuperscript{3}/h) & Diameter (mm) &  Handelsmaat diameter (mm) & Drukverval (m)\\ [0.5ex] 
 \hline\hline
 A-R & 2360 & 1242,50 & 548,81 & 570 & 0,063\\
 A-B & 50 & $\frac{3479}{6}$ & 374,91 & 407 & 0,002\\ 
 A-M & 200 & 124,25 & 173,55 & 180,8 & 0,017\\
 A-I & 750 & $\frac{5467}{12}$ & 332,32 & 361,8 & 0,032\\
 B-C & 150 & $\frac{994}{3}$ & 283,40 & 285 & 0,008\\
 B-H & 425 & $\frac{497}{3}$ & 200,40 & 203,4 & 0,032\\
 C-D & 250 & $\frac{2485}{12}$ & 224,05 & 226,2 & 0,017\\
 C-G & 425 & $\frac{497}{12}$ & 100,20 & 113 & 0,058\\
 D-E & 700 & $\frac{497}{6}$ & 141,70 & 144,6 & 0,034\\
 D-F & 500 & $\frac{497}{12}$ & 100,20 & 113 & 0,068\\
 F-G & 275 & $\frac{497}{12}$ & 100,20 & 113 & 0,037\\
 G-H & 325 & $\frac{497}{6}$ & 141,70 & 144,6 & 0,034\\
 I-J & 325 & $\frac{994}{3}$ & 283,40 & 285 & 0,017\\
 I-L & 150 & $\frac{497}{12}$ & 100,20 & 113 & 0,020\\
 J-K & 300 & $\frac{497}{3}$ & 200,40 & 203,4 & 0,023\\
 J-O & 200 & $\frac{497}{6}$ & 141,70 & 144,6 & 0,021\\
 K-N & 200 & $\frac{497}{6}$ & 141,70 & 144,6 & 0,021\\
 L-M & 750 & $\frac{497}{12}$ & 100,20 & 113 & 0,101\\[1ex] 
 \hline
\end{tabular}
\caption{De maten van de buizen in het distributiesysteem}
\label{table:distributiesysteem}
\end{table}
6
  • 1
    Welcome to TeX.SE. This code must be throwing error messages, about illegal pream-tokens being encountered, no? And, you're defining the table to have 5 columns, yet it actually has six columns.
    – Mico
    Commented Sep 26, 2023 at 9:18
  • 1
    why do you want to fix the column widths? But if you do, you need array package and wc{5cm} not c{5cm} Commented Sep 26, 2023 at 9:27
  • Mico you are right. I says this: LaTeX Error: Illegal character in array arg. Commented Sep 26, 2023 at 9:32
  • Thank you guys. This was indeed the problem Commented Sep 26, 2023 at 9:34
  • 1
    For future reference, you can't worry about the output (why is the width not the way I want it) when you have compilation errors. At that point, the output is just a guide to figure out the errors. (I find it odd that everything in column 3 is an integer multiple of 497/12.)
    – Teepeemm
    Commented Sep 26, 2023 at 13:46

3 Answers 3

2

Don't ignore LaTeX warning and error messages. For the table at hand, they arise because the c column type does not take an argument. I suppose one could superficially "fix" the syntax error by loading the array package in the preamble and changing all 5 instances of c{5cm} to wc{5cm}. However, that'll make the table much too wide to fit on a normal sheet of paper.

I can't actually detect a good reason for imposing uniform column widths. What the table desperately needs, though, is (a) an additional column spec for the first column -- I suggest using the l column type -- and (b) some semblance of structure in the cells in the header row. Specifically, I would suggest you (i) introduce a line break in the string "Handelsmaat diameter" (in order to keep the column from becoming excessively wide) and (ii) place the units of measurement on a row by themselves, for all 5 data columns. The result of making these changes, along with taking measures to force the numbers in columns 2 and 5 to be aligned on their respective implicit or explicit decimal markers, omitting all vertical rules, and using the line-drawing macros of the booktabs package instead of \hline, is shown in the following screenshot.

enter image description here

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[dutch]{babel}
\usepackage{booktabs,dcolumn}
\newcolumntype{d}[1]{D,,{#1}} % to align numbers on decimal marker
\newcolumntype{C}{>{$}c<{$}}  % centered, automatic math mode
\newcommand\mc[1]{\multicolumn{1}{c}{#1}} % handy shortcut macro

\begin{document}

\begin{table}[ht!]
\setlength\extrarowheight{3pt} % accommodate the \frac terms in column 3
\centering
\begin{tabular}{@{} l d{4.0} C c d{3.1} c @{}}
 \toprule
 Buis & \mc{Lengte}  & \mc{Debiet}  & Diameter  &  \mc{Handelsmaat}  & Drukverval \\
 & & & & \mc{diameter} \\
 & \mc{(m)} & \mc{(m\textsuperscript{3}/h)} & (mm) & \mc{(mm)} & (m) \\
 \midrule
 A-R &2360 & 1242,50         & 548,81 & 570   & 0,063\\
 A-B &  50 & \frac{3479}{6}  & 374,91 & 407   & 0,002\\
 A-M & 200 &  124,25         & 173,55 & 180,8 & 0,017\\
 A-I & 750 & \frac{5467}{12} & 332,32 & 361,8 & 0,032\\
 B-C & 150 & \frac{994}{3}   & 283,40 & 285   & 0,008\\
 B-H & 425 & \frac{497}{3}   & 200,40 & 203,4 & 0,032\\
 C-D & 250 & \frac{2485}{12} & 224,05 & 226,2 & 0,017\\
 C-G & 425 & \frac{497}{12}  & 100,20 & 113   & 0,058\\
 D-E & 700 & \frac{497}{6}   & 141,70 & 144,6 & 0,034\\
 D-F & 500 & \frac{497}{12}  & 100,20 & 113   & 0,068\\
 F-G & 275 & \frac{497}{12}  & 100,20 & 113   & 0,037\\
 G-H & 325 & \frac{497}{6}   & 141,70 & 144,6 & 0,034\\
 I-J & 325 & \frac{994}{3}   & 283,40 & 285   & 0,017\\
 I-L & 150 & \frac{497}{12}  & 100,20 & 113   & 0,020\\
 J-K & 300 & \frac{497}{3}   & 200,40 & 203,4 & 0,023\\
 J-O & 200 & \frac{497}{6}   & 141,70 & 144,6 & 0,021\\
 K-N & 200 & \frac{497}{6}   & 141,70 & 144,6 & 0,021\\
 L-M & 750 & \frac{497}{12}  & 100,20 & 113   & 0,101\\
 \bottomrule
\end{tabular}
\caption{De maten van de buizen in het distributiesysteem}
\label{table:distributiesysteem}
\end{table}

\end{document} 
1

With tblr table and tabularray libraries booktabs, siunitx (which load packages with the same name) and nccmath package (for medium size fractions: \mfrac):

Edit:
From your MWE can be concluded, that you like to have 5cm wide columns. This means that your table should be 30 cm wide! What of size are than pages in your you document? Instead of this I suggest to redesign your table as follows:

  • the first column has natural width determined by l column type
  • other five columns have equal width, determined by X column types as are provided by tabularray package.

By this the table width is equal to \textwidth in your document.

Some X columns are extended by option si which enables to align numbers at decimal markers (using siunitx package), the content od the third column is in math mode siunitx, in all are their contents centered by option c.

For more features of the tabularray package read its (concise and thorough written) documentation.

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[dutch]{babel}
\usepackage{tabularray}
\UseTblrLibrary{booktabs, siunitx}
\sisetup{per-mode = symbol,
         output-decimal-marker = {,}}
\usepackage{nccmath}


\begin{document}
    \begin{table}[ht]
\centering
\begin{tblr}{colspec = {l X[c, si={table-format=4.0}] 
                        X[c, mode=dmath] X[c] 
                        X[c, si={table-format=3.1}] X[c] },
             row{1,2} = {guard, mode=text}, 
             }
    \toprule
Buis    & Lengte    & Debiet    & Diameter      & Handelsmaat Diameter  & Drukverval        \\
        & (\unit{\meter})
                    & (\unit{\cubic\meter\per\hour}) 
                                & (\unit{\milli\meter})     
                                                & (\unit{\milli\meter}) & (\unit{meter})    \\
    \midrule
 A-R &2360 &  1242,50           & 548,81        & 570                   & 0,063             \\
 A-B &  50 & \mfrac{3479}{6}    & 374,91        & 407                   & 0,002             \\
 A-M & 200 &  124,25            & 173,55        & 180,8                 & 0,017             \\
 A-I & 750 & \mfrac{5467}{12}   & 332,32        & 361,8                 & 0,032             \\
 B-C & 150 & \mfrac{994}{3}     & 283,40        & 285                   & 0,008             \\
 B-H & 425 & \mfrac{497}{3}     & 200,40        & 203,4                 & 0,032             \\
 C-D & 250 & \mfrac{2485}{12}   & 224,05        & 226,2                 & 0,017             \\
 C-G & 425 & \mfrac{497}{12}    & 100,20        & 113                   & 0,058             \\
 D-E & 700 & \mfrac{497}{6}     & 141,70        & 144,6                 & 0,034             \\
 D-F & 500 & \mfrac{497}{12}    & 100,20        & 113                   & 0,068             \\
 F-G & 275 & \mfrac{497}{12}    & 100,20        & 113                   & 0,037             \\
 G-H & 325 & \mfrac{497}{6}     & 141,70        & 144,6                 & 0,034             \\
 I-J & 325 & \mfrac{994}{3}     & 283,40        & 285                   & 0,017             \\
 I-L & 150 & \mfrac{497}{12}    & 100,20        & 113                   & 0,020             \\
 J-K & 300 & \mfrac{497}{3}     & 200,40        & 203,4                 & 0,023             \\
 J-O & 200 & \mfrac{497}{6}     & 141,70        & 144,6                 & 0,021             \\
 K-N & 200 & \mfrac{497}{6}     & 141,70        & 144,6                 & 0,021             \\
 L-M & 750 & \mfrac{497}{12}    & 100,20        & 113                   & 0,101             \\
    \bottomrule
\end{tblr}
\caption{De maten van de buizen in het distributiesysteem}
\label{table:distributiesysteem}
    \end{table}
\end{document}

enter image description here

2
  • +1. You may want to point out explicitly that the five data columns have equal widths (though less than 5cm wide).
    – Mico
    Commented Sep 26, 2023 at 11:52
  • 1
    @Mico, done! Thank you very much for your comment. Also +1 for your nice answer!
    – Zarko
    Commented Sep 26, 2023 at 13:39
0

You are allocating quite a lot more than 25 centimeters: no reasonable paper format allows it.

I'd avoid vertical rules and double rules: they add nothing and make for hard reading.

Using siunitx we ensure correct output of numbers (the comma should not have a space behind it).

The very long headers are conveniently split into two lines.

I used \addlinespace because of the fractions.

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[dutch]{babel}

\usepackage{booktabs}
\usepackage{siunitx}

\usepackage{lipsum} % for mock content

\sisetup{
  output-decimal-marker={,}
}

\begin{document}

\lipsum[1][1-5]

\begin{table}[htp!]
\centering

\begin{tabular}{
  @{}
  l
  S[table-format=4.0]
  c
  S[table-format=3.2]
  S[table-format=3.1]
  S[table-format=1.3]
  @{}
}
\toprule
Buis & {Lengte} & Debiet & {Diameter} & {Handelsmaat} & {Drukverval} \\
& {(\unit{m})} & (\unit{m^3/h}) & {(\unit{mm})} & {diameter (\unit{mm})} & {(\unit{m})} \\
\midrule
A-R & 2360 & \num{1242,50}     & 548,81 & 570   & 0,063 \\ \addlinespace
A-B &   50 & $\frac{3479}{6}$  & 374,91 & 407   & 0,002 \\ \addlinespace 
A-M &  200 & \num{124,25}      & 173,55 & 180,8 & 0,017 \\ \addlinespace
A-I &  750 & $\frac{5467}{12}$ & 332,32 & 361,8 & 0,032 \\ \addlinespace
B-C &  150 & $\frac{994}{3}$   & 283,40 & 285   & 0,008 \\ \addlinespace
B-H &  425 & $\frac{497}{3}$   & 200,40 & 203,4 & 0,032 \\ \addlinespace
C-D &  250 & $\frac{2485}{12}$ & 224,05 & 226,2 & 0,017 \\ \addlinespace
C-G &  425 & $\frac{497}{12}$  & 100,20 & 113   & 0,058 \\ \addlinespace
D-E &  700 & $\frac{497}{6}$   & 141,70 & 144,6 & 0,034 \\ \addlinespace
D-F &  500 & $\frac{497}{12}$  & 100,20 & 113   & 0,068 \\ \addlinespace
F-G &  275 & $\frac{497}{12}$  & 100,20 & 113   & 0,037 \\ \addlinespace
G-H &  325 & $\frac{497}{6}$   & 141,70 & 144,6 & 0,034 \\ \addlinespace
I-J &  325 & $\frac{994}{3}$   & 283,40 & 285   & 0,017 \\ \addlinespace
I-L &  150 & $\frac{497}{12}$  & 100,20 & 113   & 0,020 \\ \addlinespace
J-K &  300 & $\frac{497}{3}$   & 200,40 & 203,4 & 0,023 \\ \addlinespace
J-O &  200 & $\frac{497}{6}$   & 141,70 & 144,6 & 0,021 \\ \addlinespace
K-N &  200 & $\frac{497}{6}$   & 141,70 & 144,6 & 0,021 \\ \addlinespace
L-M &  750 & $\frac{497}{12}$  & 100,20 & 113   & 0,101 \\
\bottomrule
\end{tabular}

\caption{De maten van de buizen in het distributiesysteem}
\label{table:distributiesysteem}
\end{table}

\lipsum[2]

\end{document}

enter image description here

Switching to the slashed form allows for a more compact (and more readable) table.

\begin{tabular}{
  @{}
  l
  S[table-format=4.0]
  c
  S[table-format=3.2]
  S[table-format=3.1]
  S[table-format=1.3]
  @{}
}
\toprule
Buis & {Lengte} & Debiet & {Diameter} & {Handelsmaat} & {Drukverval} \\
& {(\unit{m})} & (\unit{m^3/h}) & {(\unit{mm})} & {diameter (\unit{mm})} & {(\unit{m})} \\
\midrule
A-R & 2360 & \num{1242,50} & 548,81 & 570   & 0,063 \\
A-B &   50 & $3479/6$      & 374,91 & 407   & 0,002 \\ 
A-M &  200 & \num{124,25}  & 173,55 & 180,8 & 0,017 \\
A-I &  750 & $5467/12$     & 332,32 & 361,8 & 0,032 \\
B-C &  150 & $994/3$       & 283,40 & 285   & 0,008 \\
B-H &  425 & $497/3$       & 200,40 & 203,4 & 0,032 \\
C-D &  250 & $2485/12$     & 224,05 & 226,2 & 0,017 \\
C-G &  425 & $497/12$      & 100,20 & 113   & 0,058 \\
D-E &  700 & $497/6$       & 141,70 & 144,6 & 0,034 \\
D-F &  500 & $497/12$      & 100,20 & 113   & 0,068 \\
F-G &  275 & $497/12$      & 100,20 & 113   & 0,037 \\
G-H &  325 & $497/6$       & 141,70 & 144,6 & 0,034 \\
I-J &  325 & $994/3$       & 283,40 & 285   & 0,017 \\
I-L &  150 & $497/12$      & 100,20 & 113   & 0,020 \\
J-K &  300 & $497/3$       & 200,40 & 203,4 & 0,023 \\
J-O &  200 & $497/6$       & 141,70 & 144,6 & 0,021 \\
K-N &  200 & $497/6$       & 141,70 & 144,6 & 0,021 \\
L-M &  750 & $497/12$      & 100,20 & 113   & 0,101 \\
\bottomrule
\end{tabular}

enter image description here

You must log in to answer this question.

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