2

I'm trying to create a sort of table which: a) is the same width as my text, b) has columns with predefined widths; c) has cells which span over multiple columns; and d) wraps text in these multicolumns.

Basically, I'm trying to recreate something like this (horizontal and vertical lines are just included to see where the multicolumn cells should be, the final table should not have any lines): enter image description here

I thought I almost got it using this solution, but it creates LaTeX to crash with the errors "Forbidden control sequence found while scanning use of \NC@find. Province: &", "Missing \endgroup inserted. Province: &", and "Extra alignment tab has been changed to \cr. Province: & Baetica &".

This is the code I used to create the (non-working) table (the precise column width will probably require some more tweaking, but you should get a general idea):

\documentclass[]{article}
\usepackage{array} 
\newcolumntype{C}[1]{>{\centering\arraybackslash}p{#1}}

\begin{document}


\begin{table}[tb]
    \centering
    \begin{tabular}{p{2.5cm} p{4cm} p{2.5cm} p{4cm}}
        \textsc{edcs-id}: & \textsc{edcs}-9000163 & Dating: & 101 to 200 \\
        Publication: & \multicolumn{3}{C}{CIL 02-07, 00154} \\
        Findspot: & \multicolumn{3}{C}{Montoro / Ad Lucos / Epora} \\
        Province: & Baetica & Region: & Iberia \\
        Diocese: & Hispaniae & Loc. Indicator: & True \\
        Text: & \multicolumn{3}{C}{Di\{i\}s Manibus sacrum Antistius / Patriciensis vixit ann(os)   LXXV / p(ius) i(n) s(uis) h(ic) s(itus) e(st) s(it) t(ibi) t(erra) l(evis)} \\
        Cleantext: & \multicolumn{3}{C}{Dis Manibus sacrum Antistius Patriciensis vixit annos LXXV pius   in suis hic situs est sit tibi terra levis} \\
        Gender: & m & Legal Status: & unknown \\
        Text-Length: & 60 & Funerary: & True \\
        origo & Col. Patricia & Distance & 38 km
    \end{tabular}
\end{table}

\end{document}

Any help and pointers as to where I'm making an error and how to arrive at the desired result are very much appreciated, thanks.

2
  • 1
    you defined C to take an argument like p , \newcolumntype{C}[1]... but you used it as \multicolumn{3}{C} you would get the same error from \multicolumn{3}{p}. see the answer you cite \multicolumn{2}{C{1.5cm}} Sep 1 at 0:39
  • Ah, thanks for pointing that out; it's always a bit embarrassing if one is not even able to correctly copy someone else's code, but nevertheless good to know what went wrong. :-) Sep 1 at 14:47

2 Answers 2

0

(updated this answer to left-align the contents of the \multicolumn{3} cells)

You mention that you want to set the overall width of the table to the width of the text block; the LaTeX macro that represents this parameter is called \textwidth. Because the tabular environment does not let users set an overall target width, I would suggest switching to a tabularx environment, with a target width of \textwidth, and enable automatic line wrapping in the cells of one or more columns. Optionally, to enhance legibility, one could add some \addlinespace directives to insert whitespace padding above and below the rows with cells that combine columns 2 thru 4. See the following screenshot for the resulting "look".

enter image description here

\documentclass{article}
\usepackage{tabularx,ragged2e,booktabs} 
% Define a variable-width version of 'X' column type:
\newcolumntype{L}[1]{>{\RaggedRight\hsize=#1\hsize}X}

\begin{document}

\begin{table}[ht]
\setlength\tabcolsep{3pt} % default: 6pt
\begin{tabularx}{\textwidth}{@{} l L{1.15} L{0.8} L{1.05} @{}} % 1.15+0.8+1.05 = 3 = # of X-type columns

\textsc{edcs-id} & \textsc{edcs}-9000163 & Dating & 101 to 200 \\
Publication      & \multicolumn{3}{l}{CIL 02-07, 00154} \\
Findspot         & \multicolumn{3}{l}{Montoro\slash Ad Lucos\slash Epora} \\
Province         & Baetica     & Region & Iberia \\
Diocese          & Hispaniae   & Loc.\ Indicator & True \\
\addlinespace
Text             & \multicolumn{3}{L{3}}{Di\{i\}s Manibus sacrum Antistius\slash Patriciensis vixit ann(os) LXXV\slash p(ius) i(n) s(uis) h(ic) s(itus) e(st) s(it) t(ibi) t(erra) l(evis)} \\
\addlinespace
Cleantext        & \multicolumn{3}{L{3}}{Dis Manibus sacrum Antistius\slash Patriciensis vixit annos LXXV\slash pius in suis hic situs est sit tibi terra levis} \\
\addlinespace
Gender           & m              & Legal Status & unknown \\
Text-Length      & 60             & Funerary     & True \\
origo            & Col.\ Patricia & Distance     & 38 km

\end{tabularx}
\end{table}

\end{document}
0

Embedding paragraphs within a table has long been a weak point of the built-in tabular environment. If you use the tabularray package instead, you have more fine control over how LaTeX typesets your table. Note that your request (a) "the same width as my text" conflicts with (b) "has columns with predefined widths," and I've chosen to honor (a) rather than (b): the table produced will always be as wide as a line of the surrounding text. However, if you want to format the column lengths to be exactly 2.5 cm, 4 cm, 2.5 cm, and 4 cm, you can simply use those instead; e.g. you can delete 0.8\textwidth and replace it with a length of your choice, like 10.5cm.

A table produced by tabularray from the code below.

\documentclass{article}
\usepackage{tabularray} 

\begin{document}

\begin{table}[tb]
    \centering
    \begin{tblr}{
        colsep=0pt,
        colspec={
            Q[l,0.2\textwidth]
            Q[l,0.3\textwidth]
            Q[l,0.2\textwidth]
            Q[l,0.3\textwidth]
        }
    }
        \textsc{edcs-id}: & \textsc{edcs}-9000163 & Dating: & 101 to 200 \\
        Publication: & \SetCell[c=3]{l,0.8\textwidth}CIL 02-07, 00154 \\
        Findspot: & \SetCell[c=3]{l,0.8\textwidth} Montoro / Ad Lucos / Epora \\
        Province: & Baetica & Region: & Iberia \\
        Diocese: & Hispaniae & Loc. Indicator: & True \\
        Text: & \SetCell[c=3]{l,0.8\textwidth} Di\{i\}s Manibus sacrum Antistius / Patriciensis vixit ann(os) LXXV / p(ius) i(n) s(uis) h(ic) s(itus) e(st) s(it) t(ibi) t(erra) l(evis) \\
        Cleantext: & \SetCell[c=3]{l,0.8\textwidth} Dis Manibus sacrum Antistius Patriciensis vixit annos LXXV pius in suis hic situs est sit tibi terra levis \\
        Gender: & m & Legal Status: & unknown \\
        Text-Length: & 60 & Funerary: & True \\
        origo & Col. Patricia & Distance & 38 km
    \end{tblr}
\end{table}

\end{document}
3
  • "Embedding paragraphs within a table has long been a weak point of the built-in tabular environment." What purpose is being served by such editorializing? And why create the impression that meaningful alternatives to tabular, such as tabularx and tabular*, haven't been around for decades?
    – Mico
    Sep 1 at 0:22
  • the error in the question is simple a syntax error,a missing argument not missing functionality Sep 1 at 0:43
  • Thank you both for pointing these things out. I don't like debugging syntax errors that I don't understand, and I don't have anything against tabularx or tabular* either; I've simply not learned them before. I'm not sure there's a part of my answer where I'm implying they don't exist—if you see a way to phrase it more clearly, you're welcome to edit my answer. It's not uncommon to see solutions from multiple different approaches, and it's often helpful to new users too to see new packages. My choice here was tabularray.
    – gz839918
    Sep 1 at 2:03

You must log in to answer this question.

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